Skip to content

Fix OTtel build errors after breaking changes #94

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 3 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 4 additions & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,10 @@ dependencies {
//Distributed Tracing Dependency on OpenTelemetry and Solace OpenTelemetry JCSMP Integration
implementation group: 'com.solace', name: 'solace-opentelemetry-jcsmp-integration', version: '1.1.0'
implementation group: 'io.opentelemetry', name: 'opentelemetry-exporter-otlp', version: '1.+'
implementation group: 'io.opentelemetry.semconv', name: 'opentelemetry-semconv', version: '1.+'
//implementation group: 'io.opentelemetry.semconv', name: 'opentelemetry-semconv', version: '1.29.+'
// breaking changes in 1.30, need to change a lot of code since OTel moved around a TON of stuff, will fix once stable
implementation group: 'io.opentelemetry.semconv', name: 'opentelemetry-semconv', version: '1.30.+'
implementation group: 'io.opentelemetry.semconv', name: 'opentelemetry-semconv-incubating', version: '1.30.+'
}

sourceSets {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,9 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues;

/**
* A sample that shows how to generate a Publisher/send span with Solace OpenTelemetry Integration
Expand Down Expand Up @@ -157,17 +159,18 @@ private void messagePublisherTracer(XMLMessage message, XMLMessageProducer messa
// Some transport attributes to include, in the SemanticAttributes name space:
// See: https://opentelemetry.io/docs/specs/semconv/general/trace/

.setAttribute(SemanticAttributes.MESSAGING_SYSTEM, "solace")
.setAttribute(SemanticAttributes.MESSAGING_OPERATION, "send")
.setAttribute(SemanticAttributes.MESSAGING_DESTINATION_NAME, messageDestination.getName())
.setAttribute(SemanticAttributes.NET_PROTOCOL_NAME, "smf")
.setAttribute(MessagingIncubatingAttributes.MESSAGING_SYSTEM, "solace")
.setAttribute(MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE, MessagingOperationTypeIncubatingValues.SEND)
.setAttribute(MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME, messageDestination.getName())
.setAttribute(NetworkAttributes.NETWORK_PROTOCOL_NAME, "smf")

//.setParent(Context.current()) // set current context as parent // empty in this case, same as .setNoParent()
.setParent(manualContext) // Changes things to PropagatedSpan vs SdkSpan, but doesn't show in Jaeger.
//.setNoParent()
.startSpan();

try (Scope scope = sendSpan.makeCurrent()) {
scope.equals(null); // to not get the compile warning due to not using scope. stupid javac

// Add some OTEL Baggage (key-value store) of contextual information
// that can 'propagate' across multiple systems and spans by being copied from one to another.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,9 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues;

/**
* A sample that shows how to generate a Publisher/send span with Solace OpenTelemetry Integration
Expand Down Expand Up @@ -139,16 +141,17 @@ private void messagePublisherTracer(XMLMessage message, XMLMessageProducer messa
// Some transport attributes to include, in the SemanticAttributes name space:
// See: https://opentelemetry.io/docs/specs/semconv/general/trace/

.setAttribute(SemanticAttributes.MESSAGING_SYSTEM, "solace")
.setAttribute(SemanticAttributes.MESSAGING_OPERATION, "send")
.setAttribute(SemanticAttributes.MESSAGING_DESTINATION_NAME, messageDestination.getName())
.setAttribute(SemanticAttributes.NET_PROTOCOL_NAME, "smf")
.setAttribute(MessagingIncubatingAttributes.MESSAGING_SYSTEM, "solace")
.setAttribute(MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE, MessagingOperationTypeIncubatingValues.SEND)
.setAttribute(MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME, messageDestination.getName())
.setAttribute(NetworkAttributes.NETWORK_PROTOCOL_NAME, "smf")

.setParent(Context.current()) // set current context as parent (empty in this case, same as .setNoParent() )
.startSpan();

// This is signalling the span to have started, timestamps automatically captured.
try (Scope scope = sendSpan.makeCurrent()) {
scope.equals(null); // to not get the compile warning due to not using scope. stupid javac

// Add some OTEL Baggage (key-value store) of contextual information
// that can 'propagate' across multiple systems and spans by being copied from one to another.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,11 +15,31 @@
*/

package com.solace.samples.jcsmp.features.distributedtracing;
import com.solace.messaging.trace.propagation.SolaceJCSMPTextMapGetter;
import com.solacesystems.jcsmp.*;
import java.io.IOException;
import java.util.Map;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;

import com.solace.messaging.trace.propagation.SolaceJCSMPTextMapGetter;
import com.solacesystems.jcsmp.BytesXMLMessage;
import com.solacesystems.jcsmp.ConsumerFlowProperties;
import com.solacesystems.jcsmp.FlowEventArgs;
import com.solacesystems.jcsmp.FlowEventHandler;
import com.solacesystems.jcsmp.FlowReceiver;
import com.solacesystems.jcsmp.JCSMPChannelProperties;
import com.solacesystems.jcsmp.JCSMPErrorResponseException;
import com.solacesystems.jcsmp.JCSMPException;
import com.solacesystems.jcsmp.JCSMPFactory;
import com.solacesystems.jcsmp.JCSMPProperties;
import com.solacesystems.jcsmp.JCSMPSession;
import com.solacesystems.jcsmp.JCSMPTransportException;
import com.solacesystems.jcsmp.OperationNotSupportedException;
import com.solacesystems.jcsmp.Queue;
import com.solacesystems.jcsmp.SessionEventArgs;
import com.solacesystems.jcsmp.SessionEventHandler;
import com.solacesystems.jcsmp.XMLMessageListener;

//OpenTelemetry Instrumentation Imports:
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
Expand All @@ -29,12 +49,11 @@
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.context.Scope;
import io.opentelemetry.semconv.SemanticAttributes;

import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.semconv.NetworkAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues;

public class QueueSubscriberWithManualInstrumentation {
// remember to add log4j2.xml to your classpath
Expand Down Expand Up @@ -161,6 +180,7 @@ public void onReceive(BytesXMLMessage message) {

// Set the extracted context as current context as starting point
try (Scope scope = extractedContext.makeCurrent()) {
scope.equals(null); // to not get the compile warning due to not using scope. stupid javac

// Create a child span to signal the message receive and set extracted/current context as parent of this span
final Span receiveSpan = tracer.
Expand All @@ -180,10 +200,10 @@ public void onReceive(BytesXMLMessage message) {
// Some transport attributes to include, in the SemanticAttributes name space:
// See: https://opentelemetry.io/docs/specs/semconv/general/trace/

.setAttribute(SemanticAttributes.MESSAGING_SYSTEM, "solace")
.setAttribute(SemanticAttributes.MESSAGING_OPERATION, "receive")
.setAttribute(SemanticAttributes.MESSAGING_DESTINATION_NAME, message.getDestination().getName())
.setAttribute(SemanticAttributes.NET_PROTOCOL_NAME, "smf")
.setAttribute(MessagingIncubatingAttributes.MESSAGING_SYSTEM, "solace")
.setAttribute(MessagingIncubatingAttributes.MESSAGING_OPERATION_TYPE, MessagingOperationTypeIncubatingValues.RECEIVE)
.setAttribute(MessagingIncubatingAttributes.MESSAGING_DESTINATION_NAME, message.getDestination().getName())
.setAttribute(NetworkAttributes.NETWORK_PROTOCOL_NAME, "smf")

// Example attribute setting in a given namespace, information specific to this application
.setAttribute("com.acme.product_update.receive_key.1", "myValue1")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,19 +16,19 @@

package com.solace.samples.jcsmp.features.distributedtracing;

import java.util.concurrent.TimeUnit;

import io.opentelemetry.api.baggage.propagation.W3CBaggagePropagator;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.trace.propagation.W3CTraceContextPropagator;
import io.opentelemetry.context.propagation.ContextPropagators;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.exporter.otlp.http.trace.OtlpHttpSpanExporter;
import io.opentelemetry.exporter.otlp.trace.OtlpGrpcSpanExporter;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import io.opentelemetry.sdk.trace.export.BatchSpanProcessor;
import io.opentelemetry.semconv.ResourceAttributes;
import java.util.concurrent.TimeUnit;
import io.opentelemetry.semconv.ServiceAttributes;

// A class to facilitate OpenTelemetry Instrumentation. Can be commonly used across the application.
public class TracingUtil {
Expand All @@ -39,7 +39,7 @@ public static void initManualTracing(String serviceName) {

// OpenTelemetry Resource object
Resource resource = Resource.getDefault().merge(Resource.create(
Attributes.of(ResourceAttributes.SERVICE_NAME, serviceName)));
Attributes.of(ServiceAttributes.SERVICE_NAME, serviceName)));

// OpenTelemetry provides gRPC, HTTP and NoOp span exporter.
// Configure the endpoint details dependent on the protocol choice for your OTLP receiver endpoint
Expand All @@ -50,10 +50,10 @@ public static void initManualTracing(String serviceName) {
.build();

// If HTTP:
OtlpHttpSpanExporter spanExporterHttp = OtlpHttpSpanExporter.builder()
.setEndpoint("https://yourhost.com/opentelemetry/public/v1/traces/")
.addHeader("authorization", "dataKey example-key")
.build();
// OtlpHttpSpanExporter spanExporterHttp = OtlpHttpSpanExporter.builder()
// .setEndpoint("https://yourhost.com/opentelemetry/public/v1/traces/")
// .addHeader("authorization", "dataKey example-key")
// .build();

// Use OpenTelemetry SdkTracerProvider as TracerProvider, picking between gRPC or HTTP:
SdkTracerProvider sdkTracerProvider = SdkTracerProvider.builder()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,9 +29,12 @@
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.context.propagation.TextMapPropagator;
import io.opentelemetry.semconv.SemanticAttributes;
import io.opentelemetry.semconv.SemanticAttributes.MessagingDestinationKindValues;
import io.opentelemetry.semconv.SemanticAttributes.MessagingOperationValues;
//import io.opentelemetry.semconv.SemanticAttributes;
//import io.opentelemetry.semconv.SemanticAttributes.MessagingDestinationKindValues;
//import io.opentelemetry.semconv.SemanticAttributes.MessagingOperationValues;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes;
import io.opentelemetry.semconv.incubating.MessagingIncubatingAttributes.MessagingOperationTypeIncubatingValues;

import java.util.function.Consumer;

public class HowToImplementTracingManualInstrumentation {
Expand Down Expand Up @@ -70,6 +73,7 @@ void howToExtractTraceContextIfAnyFromSolaceMessage(XMLMessage receivedMessage,
.extract(Context.current(), receivedMessage, getter);
//and then set the extractedContext as current context
try (Scope scope = extractedContext.makeCurrent()) {
scope.equals(null); // to not get the compile warning due to not using scope. stupid javac
//...
}
}
Expand All @@ -91,12 +95,9 @@ void howToCreateSpanOnMessagePublish(XMLMessage message, XMLMessageProducer mess

//Create a new span with a current context as parent of this span
final Span sendSpan = tracer
.spanBuilder("mySolacePublisherApp" + " " + MessagingOperationValues.PROCESS)
.spanBuilder("mySolacePublisherApp" + " " + MessagingOperationTypeIncubatingValues.PROCESS)
.setSpanKind(SpanKind.CLIENT)
// published to a topic endpoint (non temporary)
.setAttribute(SemanticAttributes.MESSAGING_DESTINATION_KIND,
MessagingDestinationKindValues.TOPIC)
.setAttribute(SemanticAttributes.MESSAGING_TEMP_DESTINATION, false)
.setAttribute(MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPORARY, false)
//Set more attributes as needed
//.setAttribute(...)
//.setAttribute(...)
Expand All @@ -105,6 +106,7 @@ void howToCreateSpanOnMessagePublish(XMLMessage message, XMLMessageProducer mess

//set sendSpan as new current context
try (Scope scope = sendSpan.makeCurrent()) {
scope.equals(null); // to not get the compile warning due to not using scope. stupid javac
final SolaceJCSMPTextMapSetter setter = new SolaceJCSMPTextMapSetter();
final TextMapPropagator propagator = openTelemetry.getPropagators().getTextMapPropagator();
//and then inject current context with send span into the message
Expand Down Expand Up @@ -141,14 +143,15 @@ void howToCreateNewSpanOnMessageReceive(XMLMessage receivedMessage,

//Set the extracted context as current context
try (Scope scope = extractedContext.makeCurrent()) {
scope.equals(null); // to not get the compile warning due to not using scope. stupid javac
//Create a child span and set extracted/current context as parent of this span
final Span receiveSpan = tracer
.spanBuilder("mySolaceReceiverApp" + " " + MessagingOperationValues.RECEIVE)
.spanBuilder("mySolaceReceiverApp" + " " + MessagingOperationTypeIncubatingValues.RECEIVE)
.setSpanKind(SpanKind.CLIENT)
// for the case the message was received on a non temporary queue endpoint
.setAttribute(SemanticAttributes.MESSAGING_DESTINATION_KIND,
MessagingDestinationKindValues.QUEUE)
.setAttribute(SemanticAttributes.MESSAGING_TEMP_DESTINATION, false)
// .setAttribute(SemanticAttributes.MESSAGING_DESTINATION_KIND,
// MessagingDestinationKindValues.QUEUE)
.setAttribute(MessagingIncubatingAttributes.MESSAGING_DESTINATION_TEMPORARY, false)
//Set more attributes as needed
//.setAttribute(...)
//.setAttribute(...)
Expand Down