-
Notifications
You must be signed in to change notification settings - Fork 122
[Feature Request] Add OTEL tracing information as attribute on log messages emitted using Workflow Logger #1425
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
Comments
This is not a bug. It just can't work that way. In the TS SDK, Workflows execute in a sandboxed environment. Among other things, that implies that Workflow Code can't do any I/O, and therefore, can't interact with a regular Node.js logger. Instead, log messages emitted using the Workflow context logger are funneled through a Workflow Sink to the Runtime logger. Now, Sinks are an advanced feature of the TS SDK, but essentially, that means that messages are queued internally in the Workflow context for the duration of a Workflow Activation; at the end of an Activation, queued Sink Calls are passed from the Workflow Worker Thread, through a V8 MessagePort, back to the main SDK thread, where they get processed (in this case, passing them to the Runtime logger, which in your case would be an instance of Winston's Logger class). Note that, at the time that the call is actually passed to the Winston's Logger, execution is no longer contained by the OpenTelemetry call scope, and therefore, the OpenTelemetry Auto Instrumentation can't attach these calls to the parent context. Note also that the The solution What you can do instead is to register a
I certainly agree that it would make sense to be done out of the box by our |
Yep... That WORKED @mjameswh ! I think that piece of code could be in Thanks! |
I followed https://github.com/temporalio/samples-typescript/blob/main/interceptors-opentelemetry/src/worker.ts#L20 UPDATE: issue was that even tho we have trace and span id in logger, the node instrumentation libs don't quite respect it I had to do this: function timestampNanosToHrTime(timestampNanos: bigint): [number, number] {
// Calculate seconds by dividing nanoseconds by 1e9 and getting the whole number
const seconds = Number(timestampNanos / BigInt(1e9));
// Calculate remaining nanoseconds using modulo
const nanos = Number(timestampNanos % BigInt(1e9));
return [seconds, nanos];
}
const logLevelToSeverityNumber = {
TRACE: SeverityNumber.TRACE,
DEBUG: SeverityNumber.DEBUG,
INFO: SeverityNumber.INFO,
WARN: SeverityNumber.WARN,
ERROR: SeverityNumber.ERROR,
} as const;
Runtime.install({
logger: new DefaultLogger("ERROR", ({ message, ...entry_ }) => {
logs.getLogger("temporal-workflow").emit({
severityNumber: logLevelToSeverityNumber[entry_.level],
body: message,
severityText: entry_.level.toLowerCase(),
timestamp: timestampNanosToHrTime(entry_.timestampNanos),
observedTimestamp: timestampNanosToHrTime(entry_.timestampNanos),
attributes: entry_.meta,
});
}),
... PR for reference temporalio/samples-typescript#415 |
What are you really trying to do?
Get OpenTelemetry
trace_id
andspan_id
fields on Workflow logs.Describe the bug
The tracing fields from OpenTelemetry (
trace_id
andspan_id
) is not appearing on Workflow logs specifically.It works on Client and Activities.
Calling
worflow.log.error
:Calling
activity.log.error
Which gives
"span_id":"10036d093b04a315"
and"trace_id":"f2731bb716c062624923e55b29f8fcec"
.Minimal Reproduction
interceptors-opentelemetry
sample: https://github.com/temporalio/samples-typescript/tree/main/interceptors-opentelemetrywinston
(https://opentelemetry.io/docs/languages/js/automatic/)custom-logger
using https://github.com/temporalio/samples-typescript/tree/main/custom-loggernpm run workflow
)Environment/Versions
Additional context
From
ConsoleSpanExporter
winston
+opentelemetry
on workflow context only, because it only occurs on Workflows... everywhere else is working.The text was updated successfully, but these errors were encountered: