Git Product home page Git Product logo

Comments (7)

niko-achilles avatar niko-achilles commented on July 24, 2024

I am asking the above question because in the first experimentation with opentelemetry/api in combination with Lambda and Layer extesion installed, i get the following results:

(with this result i am out of ideas or sources to read in order to continue ... by first creating spans and adding to current active context)

So,

In method invocation of Lambda

const handler = async (event, context)=>{
const tracer = opentelemetryAPI.trace.getTracer("nameOfTracer"); // tracer is a ProxyTracer
const provider = opentelemetryAPI.trace.getTracerProvider(); // tracerProvider is a ProxyTracerProvider

const span = tracer.startSpan("do some work"); // span is undefined

const currentSpan = opentelemetryAPI.trace.getSpan(opentelemetryAPI.context.active()); // currentSpan is undefined
} 

After reading the tests of the opentelemetryAPI , i understand that when no delegate is set it should return proxy tracers and 'startSpan should return Noop Spans
Link tests: https://github.com/open-telemetry/opentelemetry-js-api/blob/main/test/proxy-implementations/proxy-tracer.test.ts

Also by logging the event object in method Lambda invocation i get Propagation Headers values for:
x-b3-spanid, x-b3-traceid, "x-b3-sampled": "1", X-Amzn-Trace-Id and traceParent

The question is how do get a Tracer from Tracer Provider in order to create spans and add spans to an active context ?

from aws-otel-lambda.

anuraaga avatar anuraaga commented on July 24, 2024

Hi @niko-achilles - we store the lambda span into the current context here

https://github.com/open-telemetry/opentelemetry-js-contrib/blob/main/plugins/node/opentelemetry-instrumentation-aws-lambda/src/instrumentation.ts#L184

Without it other instrumentation would not connect to the trace.

So your code snippet seems like it's supposed to work. Are you able to create a small repro?

from aws-otel-lambda.

niko-achilles avatar niko-achilles commented on July 24, 2024

Hi @anuraaga , thanks for the link, nice to learn from this.

So,
i created a small repo here : https://github.com/niko-achilles/lambda-otel-spans/blob/main/functions/hello.js

Notice in this line that i get a ProxyTracer from provider : https://github.com/niko-achilles/lambda-otel-spans/blob/main/functions/hello.js#L25

and here the getSpanis undefined: https://github.com/niko-achilles/lambda-otel-spans/blob/main/functions/hello.js#L13

Can you help on how to get a tracer in order to create Spans and how to get the active context ?

from aws-otel-lambda.

anuraaga avatar anuraaga commented on July 24, 2024

Thanks for the repro @niko-achilles. Just wondering, do you see the behavior on all requests, not just the first?

Here's where we set a "real" tracer

https://github.com/open-telemetry/opentelemetry-lambda/blob/main/nodejs/packages/layer/src/wrapper.ts#L88

Due to the design of detectResources though it's asynchronous, and I guess it is possible for the first execution of a handler to happen before it completes. If this is the issue, there seems to be a long-standing PR on helping with it

open-telemetry/opentelemetry-js#1484

Will ping it

from aws-otel-lambda.

niko-achilles avatar niko-achilles commented on July 24, 2024

hi @anuraaga

i modified the code to add timer execution, in order to
a. execute after the tracer starts a Span with the purpose to get the span created
b. execute after the tracer ends the created span with the purpose to see the app-developer created traces in X-RAY

https://github.com/niko-achilles/lambda-otel-spans/blob/main/functions/hello.js#L23

Additionally i invoked the function under oberservabilty 50 times via a script in order to be able to answer your question about
Just wondering, do you see the behavior on all requests, not just the first?

Yes the behavior is the same .
I get in the setup, results :

/* -- Tracer instance Log --
tracer ProxyTracer {
_provider: ProxyTracerProvider {},
name: 'helloTracer',
version: '1.0'
} */

and created spans as undefined

from aws-otel-lambda.

niko-achilles avatar niko-achilles commented on July 24, 2024

update i also added a waiting behavior before getting a tracer ,
https://github.com/niko-achilles/lambda-otel-spans/blob/main/functions/hello.js#L38

but i get the same results:
/* -- Tracer instance Log --
tracer ProxyTracer {
_provider: ProxyTracerProvider {},
name: 'helloTracer',
version: '1.0'
} */

and created spans as undefined

from aws-otel-lambda.

niko-achilles avatar niko-achilles commented on July 24, 2024

@anuraaga with interacting with openetelemetry-js community contrib. i managed to get information for a workaround , in order to create custome span names.

I unistalled "@opentelemetry/api": "^1.0.0" and installed "@opentelemetry/api": "^1.0.0-rc.0".

Then i get a NodeTraceProvider and with openetelemetry api i can set/get Spans .

from aws-otel-lambda.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.