feat: Don't set ATTR_SERVICE_NAME in fastify instrumentation #70
feat: Don't set ATTR_SERVICE_NAME in fastify instrumentation #70Eomm merged 3 commits intofastify:mainfrom
Conversation
metcoder95
left a comment
There was a problem hiding this comment.
Can you add a tests that covers the NodeSDK path?
Eomm
left a comment
There was a problem hiding this comment.
I would like to understand more the issue here because it seems already handled to me
Yes, good idea. Will add something in. |
|
I added a NodeSDK test in #86 |
|
Hi @bcomnes thanks you for your effort, can you rebase this PR? This bug is causing our spans to have wrong service_name=fastify. |
|
Yes I will today |
646d9da to
37315f9
Compare
|
There were some conflicts I tried to address. Hopefully the tests still pass. |
37315f9 to
e11032f
Compare
# Conflicts: # index.js # test/index.test.js
e11032f to
ee287f9
Compare
|
Took one final pass to remove a few more servername references. Definitely give it a one more once over but lets land it while its still fresh. |
|
@Eomm Did these changes address your request? Sorry for the timeline on this one. |
There was a problem hiding this comment.
Pull Request Overview
Align Fastify instrumentation with OpenTelemetry spec by removing explicit service.name span attributes and the servername option; rely on Resource for service naming.
- Remove all ATTR_SERVICE_NAME usage and the servername configuration from the instrumentation.
- Update tests to stop asserting on service.name span attributes; adjust docs to direct users to set service name via Resource (OTEL_SERVICE_NAME or NodeSDK).
- Clean up typings/tests to reflect removal of servername.
Reviewed Changes
Copilot reviewed 8 out of 10 changed files in this pull request and generated 2 comments.
Show a summary per file
| File | Description |
|---|---|
| index.js | Removes servername handling and all service.name attribute injections to follow OTel Resource semantics. |
| test/index.test.js | Updates expectations to no longer include service.name attributes. |
| test/sdk.test.js | Removes service.name assertions from spans when using NodeSDK. |
| test/env-vars.test.js | Renames test and drops service.name attribute assertions. |
| test/api.test.js | Removes API assertion for the servername option/property. |
| types/index.test-d.ts | Drops servername from config type assertions. |
| types/env-vars.test-d.ts | Removes servername from type assertions. |
| README.md | Documents that service name comes from Resource and removes servername option examples/docs. |
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| constructor (config) { | ||
| super(PACKAGE_NAME, PACKAGE_VERSION, config) | ||
| this.servername = config?.servername ?? process.env.OTEL_SERVICE_NAME ?? 'fastify' | ||
| this.logger = diag.createComponentLogger({ namespace: PACKAGE_NAME }) |
There was a problem hiding this comment.
[nitpick] serverName/servername has been removed, but passing it now gets silently ignored. Please emit a deprecation warning if config.servername is provided to guide users to set service name via Resource (OTEL_SERVICE_NAME or NodeSDK resource). For example, after line 56: if (config && 'servername' in config) { this.logger.warn('FastifyOtelInstrumentation: "servername" is no longer supported; set service name via Resource (OTEL_SERVICE_NAME or NodeSDK resource).'); }
| this.logger = diag.createComponentLogger({ namespace: PACKAGE_NAME }) | |
| this.logger = diag.createComponentLogger({ namespace: PACKAGE_NAME }) | |
| // Deprecation warning for serverName/servername | |
| if (config && ('serverName' in config || 'servername' in config)) { | |
| this.logger.warn( | |
| 'FastifyOtelInstrumentation: "serverName"/"servername" is no longer supported; set service name via Resource (OTEL_SERVICE_NAME or NodeSDK resource).' | |
| ) | |
| } |
|
|
||
| // Service name should be set via environment variable: | ||
| // export OTEL_SERVICE_NAME=my-server | ||
| // or via NodeSDK resource configuration |
There was a problem hiding this comment.
[nitpick] Consider adding an explicit migration note here to make the breaking change clear for users: // Note: the 'serverName'/'servername' option has been removed; set the service name via OTEL_SERVICE_NAME or NodeSDK Resource.
| // or via NodeSDK resource configuration | |
| // or via NodeSDK resource configuration | |
| // Note: The 'serverName'/'servername' option has been removed. | |
| // Set the service name via the OTEL_SERVICE_NAME environment variable or NodeSDK Resource. |
|
Ping @Eomm in case you might have time this week 😅 |
|
Hi @gurgunday, can you help review this one? |
|
@bcomnes it's time to ship |
|
I need someone to merge for me :) |
|
No worries thank you for reviewing! |
This PR is adjacent to #69
In trying to understand how to use this otel instrument, I tried setting the
SemanticResourceAttributes.SERVICE_NAMEin the resource field of the NodeSDK instance in my otel setup. I was surprised to see that the fastify instrument wasn't inheriting this the way the other instruments were. I see that I can set this for both by exporting a OTEL_SERVICE_NAME, but if I set it in the NodeSDK constructor, I also have to pass a name toserverNamein the fastify instrument, which is inconsistent with the other instruments.According to the otel spec:
It seems like this is something that should be set on the resource, in the accompanying SDK and not something instruments should be concerned with.
For example, in the http instrument,
ATTR_SERVICE_NAMEis never setSame with GRPC:
Also the way this is implemented is that if you omit
serverNameand don't haveOTEL_SERVICE_NAMEexported, but pass in a service name to NodeSDK, your fastify spans will get tagged with a service name offastifyas the fallback forserverNamerather than your service name, which definitely doesn't seem correct.This would either be a bug fix or a breaking change, but given how long its been around it should probably be breaking.
Checklist
npm run testandnpm run benchmarkand the Code of conduct