Skip to content

jmhofer/opentracing-sqs-java

 
 

Repository files navigation

opentracing-sqs-java

Build Status codecov.io Maven Central License

A little Java utility library for simplifying instrumentation of SQS messages with OpenTracing.

Features

  • Serialization and deserialization of the span context as a SQS message attribute
  • Helper to easily create a span for tracing a message across SQS
  • Works with both AWS SDK 1.0 and AWS SDK 2.0

Dependencies

  • Java 8
  • AWS SDK 1.0 or AWS SDK 2.0
  • OpenTracing

Installation

This library is published to Maven Central.

You can add it as a dependency to your build (check the badge above for the current version number), for example in Gradle via

compile "org.zalando:opentracing-sqs:${opentracingSqsVersion}"

or in Maven via

<dependency>
  <groupId>org.zalando</groupId>
  <artifactId>opentracing-sqs</artifactId>
  <version>${opentracingSqsVersion}</version>
</dependency>

or in SBT via

libraryDependencies += "org.zalando" % "opentracing-sqs" % opentracingSqsVersion

Attention: Please also remember to explicitly depend on either AWS SDK 1.0 or 2.0 with your project, as these dependencies are not included transitively with this library.

Usage

Injecting the span context into a send request

SQSTracing tracing = new SQSTracing(tracer);

// works similarly for SendMessageBatchRequestEntry and SendMessageBatchRequest,
// as well as with the respective equivalent builders in AWS SDK 1.0
SendMessageRequest request = SendMessageRequest.builder()
    .messageBody("body")
    .queueUrl("queue-url")
    .build();

SendMessageRequest tracedRequest = tracing.injectInto(request); // injects the currently active span context

Extracting the span contexts from a received batch of messages

SQSTracing tracing = new SQSTracing(tracer);

ReceiveMessageResponse response = ... // retrieved from SQS, remember to request the message attributes! 

// the following works the same for ReceiveMessageResult from AWS SDK 1.0

Map<String, SpanContext> spanContexts = tracing.extractFrom(response);

// the map now contains all message ids of messages which had span contexts associated, 
// mapped to the respective span contexts

Creating and activating a span for publishing a message to SQS

SQSTracing tracing = new SQSTracing(tracer);

Span span = tracing.createActiveQueueingSpan(
    "https://sqs.us-east-2.amazonaws.com/123456789012/MyQueue", 
    "publish-update-event");

// span is created and active now, you can continue by injecting it into your request(s), for example:
SendMessageBatchRequestEntry entry = ...
SendMessageBatchRequestEntry tracedEntry = tracing.injectInto(entry, span); 

Contributing

This project happily accepts contributions from the open-source community.

Please read CONTRIBUTING.md.

Please also note our CODE_OF_CONDUCT.md.

Contact

These email addresses serve as the main contact addresses for this project.

Bug reports and feature requests are more likely to be addressed if posted as issues here on GitHub.

License

This project is licensed under the terms of the MIT license, see also the full LICENSE.

The MIT License (MIT)

Copyright (c) 2018 Zalando SE

Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:

The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.

THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

About

An attempt at a simple SQS helper library for OpenTracing support.

Resources

License

Code of conduct

Security policy

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Java 100.0%