Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(instrumentation)!: simplify registerInstrumentations() API #4675

Open
wants to merge 8 commits into
base: main
Choose a base branch
from

Conversation

pichlermarc
Copy link
Member

@pichlermarc pichlermarc commented May 3, 2024

The @opentelemetry/instrumentation package exports a InstrumentationOption type:

export type InstrumentationOption =
  | typeof InstrumentationBase
  | (typeof InstrumentationBase)[]
  | Instrumentation
  | Instrumentation[];

However, InstrumentationBase implements Instrumentation already. Further, this requires extra code to make whats passed to instrumentations just slightly more convenient, for instance it supports:

  • A single instrumentation: registerInstrumentations({instrumentations: fooInstrumentation})
  • A few instrumentations, nested in sub-arrays: registerInstrumentations({instrumentations: [fooInstrumentation, [barInstrumentation]]})

This PR proposes removing this InstrumentationOption type, and replacing all usages of InstrumentationOption and InstrumentationOption[] with (Instrumentation | Insturmentation[])[]. This drops support for the first case listed above in favor of always having to provide a list of instrumentations. This simplifies the code in both sdk-node and instrumentation.

@pichlermarc pichlermarc marked this pull request as ready for review May 6, 2024 08:56
@pichlermarc pichlermarc requested a review from a team as a code owner May 6, 2024 08:56
@trentm
Copy link
Contributor

trentm commented May 6, 2024

These aren't arguments against. I'm just pointing them out for discussion.


One convenience of having allowed nested arrays was something like:

const sdk = new NodeSDK({
    instrumentations: [
        getNodeInstrumentations(/* ... */), // this ends up being a nested array
        someThirdPartyInstrumentation,
        someOtherThirdPartyInstrumentation,
    ]
});

The fairly simple workaround is to call .flat() oneself:

sdk = new NodeSDK({
    instrumentations: [
        getNodeInstrumentations(/* ... */), // this ends up being a nested array
        someThirdPartyInstrumentation,
        someOtherThirdPartyInstrumentation,
    ].flat()
});

So I suppose that is fine.

  1. IIUC this also drops support for passing in an uninstantiated Instrumentation class:
sdk = new NodeSDK({
    instrumentations: [
        HttpInstrumentation,  // class <--- this thing would no longer be supported
        new ExpressInstrumentation(),  // instance
    ]
});

To be honest, I was surprised that passing in just the class was supported at all when I first noticed it a while back.

@pichlermarc
Copy link
Member Author

@trentm I see, I did not consider that. Actually keeping support for this is pretty straightforward so I'd keep it around, but only drop the InstrumentationBase one, so I've replaced InstrumentationOptions with (Instrumentation | Instrumentation[])[] which is reasonably simple to deal with when used. 065566d

Since opening the PR I've also seen that we recommend this way in our docs so it's probably better to keep it around.

To be honest, I was surprised that passing in just the class was supported at all when I first noticed it a while back.

Yes I'm also surprised that this works. I updated the changelog to reflect that this is not an option anymore. 970e57b

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants