Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mskcc/smile-commons
Centralized configurations for checkstyle plugin and dependency management.
https://github.com/mskcc/smile-commons
Last synced: about 1 month ago
JSON representation
Centralized configurations for checkstyle plugin and dependency management.
- Host: GitHub
- URL: https://github.com/mskcc/smile-commons
- Owner: mskcc
- License: agpl-3.0
- Created: 2020-12-09T18:13:38.000Z (about 4 years ago)
- Default Branch: master
- Last Pushed: 2024-03-12T21:10:23.000Z (9 months ago)
- Last Synced: 2024-06-21T15:38:08.656Z (6 months ago)
- Language: Java
- Size: 188 KB
- Stars: 1
- Watchers: 3
- Forks: 4
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# SMILE Commons
Centralized configurations for checkstyle plugin and dependency management.
## OpenTelemetryUtils
This common library contains utilities to supoprt [Distributed Tracing](https://lightstep.com/opentelemetry/tracing) - [Context Propagation](https://lightstep.com/opentelemetry/context-propagation) via OpenTelemetry.
### Basic Usage for application
```java
// required imports
import org.mskcc.smile.commons.OpenTelemetryUtils;
import org.mskcc.smile.commons.OpenTelemetryUtils.TraceMetadata;// inject
@Autowired
OpenTelemetryUtils openTelemetryUtils;// OpenTelemetry Tracer
private static final Tracer tracer = GlobalOpenTelemetry.get().getTracer("org.mskcc.cmo.Classname");// Upstream service propagating context to downstream service via a Nats Message
Span testJetstreamPubSpan = tracer.spanBuilder("testJetStreamPubSpan").startSpan();
Scope scope = testJetstreamPubSpan.makeCurrent();
Span.current().addEvent("testJetstreamPubEvent: publishing to jetstream topic" + JETSTREAM_PUBLISH_TOPIC);
TraceMetadata tmd = openTelemetryUtils.getTraceMetadata();
messagingGateway.publishWithTrace(JETSTREAM_PUBLISH_TOPIC, "", tmd);
testJetstreamPubSpan.end();// Downstream service receiving context via onMessage subscription and continuing tracing using the same span
@Override
public void onMessage(Message msg, Object message)
{
try {
// In production code, the following statement should check if TraceMetadata exists before usin it.
String traceId = msg.getHeaders().get(TraceMetadata.getHeaderKey()).get(0);
TraceMetadata tmd = new TraceMetadata(traceId);
Span testJetstreamSubOnMessageSpan = openTelemetryUtils.getSpan(tmd, "testJetStreamSubOnMessageSpan");Scope scope = testJetstreamSubOnMessageSpan.makeCurrent();
String receivedMessageContent = new String(msg.getData(), StandardCharsets.UTF_8);
Attributes eventAttributes = Attributes.of(AttributeKey.stringKey("receivedMessageSubject"), msg.getSubject(),
AttributeKey.stringKey("receivedMessageBody"), receivedMessageContent);
Span.current().addEvent("testJetstreamSubOnMessageEvent: messageReceived", eventAttributes);
testJetstreamSubOnMessageSpan.end();
}
catch (Exception e) {
System.out.println("Exception: " + e.getMessage());
}
}
```