You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Hello. I am encountering the following situation.
My company uses nodejs v20.15.1, and ddtrace v4.17.0. I was asked to include data about the user each time I log information. So if I logger.log('message'), in Datadog the content should also have the request's user information.
To do this, I thought about setting up that data in one of the first spans, and then access that data from the logger.
So basically, I have a middleware like this, that is called before a network request:
if (span) {
datadog.tracer.inject(span.context(), formats.LOG, record);
// Add security context data from span baggage items
const value = span.getBaggageItem('user.accountId');
if (value !== undefined) {
record[item] = value;
}
}
console.log(safeStringify({ ...record, extraPayload }));
}
}
The problem is that the item is always empty. The data is never saved. Even if I add to the baggage items list, and try to get the item right away, I still get empty data.
There are a few clarifications:
The reason why I am using setBaggageItem instead of setTag, is that I can actually access the baggage item after using the API. I read this issue (Support iterating over baggage items #2409) and apparently one can also access the items via field span.context()._baggageItems but it tells me there is no such attribute. It seems that its not supported in the version that I have, but that is not good practice in the first place.
Another reason is that, setBaggageItem, according to the documentation, actually propagates the data across spans, and with tags that does not happen.
The text was updated successfully, but these errors were encountered:
Also, from ChatGPT, consider the difference between how OpenTelemetry handles baggage (with Baggage.Current) vs how SignalFx handles it:
The concept of Baggage.Current specifically exists in OpenTelemetry but not directly in the SignalFx tracing library.
SignalFx’s tracing library uses OpenTracing, which has some support for baggage items but handles them differently.
Key Differences:
OpenTelemetry:
In OpenTelemetry, Baggage.Current is part of the context propagation API, allowing baggage to be automatically attached to the current execution context.
OpenTelemetry provides a more standardized API for baggage that is consistent across languages and has explicit support for accessing and managing baggage as Baggage.Current, making it accessible across distributed traces in a clean, structured way.
SignalFx / OpenTracing:
In SignalFx’s OpenTracing-based library, there’s no direct equivalent to Baggage.Current. Instead, you use baggage through the span context and methods like SetBaggageItem and GetBaggageItem on spans.
Baggage items can still be propagated, but it’s up to you to extract them manually and set them on each new span within the same trace. The baggage propagation is less automatic and less integrated into the tracing context compared to OpenTelemetry.
That .NET implementation may not be entirely relevant to the JS implementation, but it is an example where it's just not supported in a DataDog implementation of OpenTracing.
Hello. I am encountering the following situation.
My company uses nodejs v20.15.1, and ddtrace v4.17.0. I was asked to include data about the user each time I log information. So if I logger.log('message'), in Datadog the content should also have the request's user information.
To do this, I thought about setting up that data in one of the first spans, and then access that data from the logger.
So basically, I have a middleware like this, that is called before a network request:
export const jwtDatadogHook = (req: any, _res: any, next: NextFunction) => {
const scope = datadog.tracer.scope()?.active();
const ctx: SecurityContext = req.securityContext;
next();
};
...
router.use(jwtDatadogHook);
...
And then, each time I log when processing the request:
private log(level: 'BIZ' | 'ERROR' | 'WARN' | 'INFO' | 'DEBUG', payload: any, extraPayload?: any) {
const span = datadog.tracer.scope().active();
const timestamp = new Date().toISOString();
const record = {
... this.defaultPayload,
... (typeof payload === 'string' ? { message: payload } : payload),
timestamp,
level
};
}
The problem is that the item is always empty. The data is never saved. Even if I add to the baggage items list, and try to get the item right away, I still get empty data.
There are a few clarifications:
The reason why I am using setBaggageItem instead of setTag, is that I can actually access the baggage item after using the API. I read this issue (Support iterating over baggage items #2409) and apparently one can also access the items via field span.context()._baggageItems but it tells me there is no such attribute. It seems that its not supported in the version that I have, but that is not good practice in the first place.
Another reason is that, setBaggageItem, according to the documentation, actually propagates the data across spans, and with tags that does not happen.
The text was updated successfully, but these errors were encountered: