-
I have a lambda that publishes a message to aws sqs queue using OpenTelemetry 0.18.0. I'm able to get Is that the correct object to send for downstream processing? Sending lambda - message attribute is created with the below snippet: ...
function createAttributes(entity, ctxTrace) {
return {
traceHeaders: { DataType: "String", StringValue: JSON.stringify(ctxTrace)
};
}
const params = {
MessageAttributes: createAttributes(entity, parentSpan.context());
};
... Receiving Lambda - const { tracing } = require('./tracing');
const optl = require('@opentelemetry/api');
...
exports.handler = async(event, context) => {
// manually trying to get it to work and then will pull from message header. I've tried several different things but this seems to be the closest
const traceHeader = JSON.parse("{\"traceId\":\"c878ad222c04776c3b3dbbbe9156170c\",\"spanId\":\"0b0ed509527d73ab\",\"traceFlags\":1}");
const tracer = tracing;
const parentSpan = tracer.startSpan('test_span', {}, optl.setSpan(optl.context.active(), traceHeader));
// This gives an error message of TypeError: _a.context is not a function
} tracing file const opentelemetry = require('@opentelemetry/api');
const { LogLevel } = require("@opentelemetry/core");
const { NodeTracerProvider } = require("@opentelemetry/node");
const { BatchSpanProcessor } = require("@opentelemetry/tracing");
const { CollectorTraceExporter } = require("@opentelemetry/exporter-collector");
const { B3Propagator } = require("@opentelemetry/propagator-b3");
const exporter = new CollectorTraceExporter({
serviceName: process.env.SERVICE_NAME,
headers:{
'Lightstep-Access-Token': process.env.LIGHTSTEP_TOKEN
},
url:'https://ingest.lightstep.com:443/api/v2/otel/trace',
});
const provider = new NodeTracerProvider();
provider.addSpanProcessor(new BatchSpanProcessor(exporter));
provider.register({
propagator: new B3Propagator(),
});
const tracer = opentelemetry.trace.getTracer(process.env.SERVICE_NAME);
exports.tracing=tracer; Any guidance would be appreciated. UPDATE: With the help of Flarna's comment and the one below. I was able to put all the pieces together using the provided B3Propagator. The thing that was messing me up was I wasn't aware how much things changed from version 0.14.0 to 0.18.0 in relation to creating child spans of parents. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 1 reply
-
What you create here is named propagator, see e.g. HttpTraceContext how to covert you strings into a context. Maybe it is even possible to use the |
Beta Was this translation helpful? Give feedback.
-
@dhenard can you share a code snipped that worked for you? |
Beta Was this translation helpful? Give feedback.
What you create here is named propagator, see e.g. HttpTraceContext how to covert you strings into a context.
Maybe it is even possible to use the
HttpTraceContext
as is and just pass custom getter/setter to extract/inject. But I assume this would require to put each string into a separate attribute.