Skip to content
Discussion options

You must be logged in to vote

Yes, that should generally be possible.

Using the aws-otel-nodejs layer for auto-instrumentation does not stop you from also using the OpenTelemetry API in your own code to enrich the current span with custom attributes.

So the basic idea you showed is the right one:

const { trace } = require("@opentelemetry/api");

function handleUser(user) {
  const activeSpan = trace.getActiveSpan();
  if (activeSpan) {
    activeSpan.setAttribute("user.id", user.getId());
  }
}

The main thing I’d add is the null check, because getActiveSpan() can return nothing if that code runs outside an active traced context.

So the short answer is:

  • yes, you can keep using the AWS OTel Node.js layer
  • yes, you can s…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@spongenee
Comment options

Answer selected by spongenee
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants