Comments (6)
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.
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.
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.
Thanks. I will look at those packages and the Logs Bridge API, thanks for all the tip and pointers!
from opentelemetry-js.
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.
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)
- Implement xray-lambda propagator via the OTEL_PROPAGATORS env variable HOT 5
- [@opentelemetry/instrumentation-fetch] Memory leak in NextJS app HOT 8
- ENOENT: no such file or directory, open '/home/webapp/.aws/config' HOT 4
- Baggage : How to use baggae with auto instrumentation web HOT 2
- `@opentelemetry/instrumentation` requires old `@opentelemetry/api-logs` peer dep
- Package subpath './build/src/trace/NoopTracer' is not defined by "exports" HOT 5
- HTTP Timeouts don't seem to retry, resulting in dropped spans HOT 1
- Allow adding links after span creation HOT 2
- Give us the ability to set default option on SugaredTracer
- [instrumentation] replace `cpx2` with a local module in `tests/fixtures/` exclusively for testing
- Implement Jaeger Remote Sampler as defined by the specification HOT 2
- TypeError: timer.unref is not a function HOT 7
- [otlp-exporters] passing an `undefined` header values crashes end-user apps
- [all] replace package.json#browsers with package.json#exports.browser HOT 1
- Is there a recommended pattern for manually nesting asynchronous trace spans in the browser? HOT 2
- `@opentelemetry/instrumentation/hook.mjs` crashes when loading a module containing `export * from` syntax HOT 3
- Avoid the SemVer v0.x.x anti-pattern HOT 11
- [sdk-node] automatically configure metrics exporter based on enviornment variables
- [sdk-node] automatically configure logs exporter based on enviornment variables HOT 2
- [instrumentation] support ESM instrumentation for Node.js v18.19, v20, v21 HOT 9
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
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.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from opentelemetry-js.