Giter Site home page Giter Site logo

Comments (6)

pichlermarc avatar pichlermarc commented on June 30, 2024 1

As of today, the OpenTelemetry API specification does not include a way to retrieve the resource, therefore this is also not exposed in the JavaScript OTel API.

Are you using OTel for logging or some other solution? If you're using OTel, then all logs that are being exported will have the resource added to it.

from opentelemetry-js.

pichlermarc avatar pichlermarc commented on June 30, 2024 1

I am looking at the instrumentation package for Pino and don't see where it is retrieving the resource attributes. In the README.md, it also says it only adds trace_id, span_id, and trace_flags.

A pino logs bridge is not implemented yet, only bunyan has a working logs instrumentation at the moment. One for winston is in the works right now.

Or do you mean using @opentelemetry/api-logs and @opentelemetry/sdk-logs? In that case, I am assuming the LoggerProvider holds a reference to the resource.

Yes, for logging (for instance with bunyan), the resource will be associated with the logs that are being exported via OTLP, as it has a bridge that passes the logs created via bunyan to @opentelemtry/api-logs.

So if I do want to roll my own, I'd have to hold my own reference to the resource, and manually pass that into the SDK as well as to my application.

Also yes. But keep in mind: keeping the resource around and using it in your app goes against the way OTel is supposed to be used. In your app, after setting up in ./instrumentation.js you should only be using the @opentelemetry/api package, and should never reference SDK components like the Resource again. This is set up in this way so that you can make a localized change (in instrumentation.js) once there's an SDK 2.0, while keeping all your application code that depends on the API package which does not significantly change and is planned to stay stable for a much longer time than the SDK would.

To summarize a Resource is intended to be used with OTel SDKs, and any other uses are not something we'd recommend or support.

That being said, all information that's set in the resource can be somewhat easily be recreated by using the resource detectors again that are exported from the @opentelemetry/resouces package (hostDetectorSync, osDetectorSync, envDetectorSync, ...) and merging it together manually using Resource.merge()

from opentelemetry-js.

dayuloli avatar dayuloli commented on June 30, 2024

Are you using OTel for logging or some other solution? If you're using OTel, then all logs that are being exported will have the resource added to it.

We have our own custom logger so can't use one of the ready-made instrumentation packages.

I am looking at the instrumentation package for Pino and don't see where it is retrieving the resource attributes. In the README.md, it also says it only adds trace_id, span_id, and trace_flags.

Or do you mean using @opentelemetry/api-logs and @opentelemetry/sdk-logs? In that case, I am assuming the LoggerProvider holds a reference to the resource. So if I do want to roll my own, I'd have to hold my own reference to the resource, and manually pass that into the SDK as well as to my application.

from opentelemetry-js.

dayuloli avatar dayuloli commented on June 30, 2024

Thanks. I will look at those packages and the Logs Bridge API, thanks for all the tip and pointers!

from opentelemetry-js.

sarfarazahmedkl avatar sarfarazahmedkl commented on June 30, 2024
        import opentelemetry, * as api from '@opentelemetry/api';
        const tracer = opentelemetry.trace.getTracer(
            'service-name',
            'service-version',
         );
        const span = tracer.startSpan('span-name');
        let activeContext: any = api.propagation.extract(api.context.active(), {});
        let key = api.createContextKey('OpenTelemetry Context Key SPAN')
        let attributeValue = activeContext.getValue(key)?.attributes['attribute-name']

All attributes related to span will be saved to the 'OpenTelemetry Context Key SPAN' context, so we can access attribute value from the app.js file as mentioned above.

from opentelemetry-js.

pichlermarc avatar pichlermarc commented on June 30, 2024
        import opentelemetry, * as api from '@opentelemetry/api';
        const tracer = opentelemetry.trace.getTracer(
            'service-name',
            'service-version',
         );
        const span = tracer.startSpan('span-name');
        let activeContext: any = api.propagation.extract(api.context.active(), {});
        let key = api.createContextKey('OpenTelemetry Context Key SPAN')
        let attributeValue = activeContext.getValue(key)?.attributes['attribute-name']

All attributes related to span will be saved to the 'OpenTelemetry Context Key SPAN' context, so we can access attribute value from the app.js file as mentioned above.

context.getValue() returns unknown on purpose. It may be there today but keep in mind that this approach may break at any time without warning in the future.

from opentelemetry-js.

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.