open-telemetry / opentelemetry-js

OpenTelemetry JavaScript Client
https://opentelemetry.io
Apache License 2.0
2.54k stars 740 forks source link

How to make metadata accessible #4725

Open blumamir opened 1 month ago

blumamir commented 1 month ago

I am exploring ways to enhance our handling of metadata for instrumentations, aiming to streamline processes and boost efficiency.

Instrumentation (or OpenTelemetry component) metadata comprises static information about OpenTelemetry JS instrumentation (or other components) that is valuable for distributions, control planes, APMs, and similar tools.

We currently record the name and version for each instrumentation, which also serves as the scope name for the signals we emit

Although metadata is not recorded into signals, it can significantly enhance user experience and automate tasks when utilized by distributions, offering a smoother and more intuitive interface.

Metadata Examples

and more info that we might need oneday...

Essentially, any information that might be useful for users to consume through various interfaces (documentation, README, UI, links, status) in its raw format

Usages

Here are a few practical applications of how this metadata can be effectively utilized:

Suggestion

I want to suggest aggregating the metadata to achieve the goals above. I can work on the relevant PRs to implement something if there is an agreement. I will start with just the info we already have available, and then introduce a script for the auto-instrumentations-node README auto-generation and enhancement. Additionally, I plan to utilize this data for the odigos distribution of js agent to auto-generate a Node.js section in the Odigos documentation and potentially report back instrumentation statuses to the Odigos control plane based on this data.

Some objectives to consider:

Options

  1. The simplest and straight forward way would be to add this data to instrumentation interface, and then have each instrumentation setting it up:
    • as constructor argument, similar to instrumentation name and version which are already passed this way
    • as a function that instrumentation can override and return a metadata object, like the current init() function for patched packages info.
    • by defining an optional property from the base class which will expose this data on instrumentation instances.

If we decide to proceed this way, we must address TypeScript compatibility issues across versions to ensure that adding new properties does not introduce complexity.

Consider omitting it from web components at the moment so not to increase bundle size.

  1. save this data as a json file for each package, and publish it to npm alongside the instrumentations. Then tools can maybe pick the node_modules folder to extract this info from code, and remote users can git pull to the tag or make an http request to fetch the data when needed. See Collector metadata.yaml as an inspiration.

Considerations

I think that once we come up with a good way to record this info, introducing it to existing components is a relatively simple technical task which I am up for doing.

I would appreciate your thoughts, concerns, suggestions or support, to help make this initiative a success!

pichlermarc commented 1 week ago

As discussed offline I'd be in favor of Option 2, or maybe even including the data in package.json as it's allowed to put extra fields in there - which can open additional avenues for other use-cases as well (auto-finding instrumentation packages via the registry). :slightly_smiling_face:

blumamir commented 1 week ago

As discussed offline I'd be in favor of Option 2, or maybe even including the data in package.json as it's allowed to put extra fields in there - which can open additional avenues for other use-cases as well (auto-finding instrumentation packages via the registry). 🙂

Thank you marc. I really like the idea of adding it to package.json.

Opened the first PR to add metadata this way here