Skip to content

Conversation

@bcomnes
Copy link
Contributor

@bcomnes bcomnes commented Jun 24, 2025

This PR is adjacent to #69

In trying to understand how to use this otel instrument, I tried setting the SemanticResourceAttributes.SERVICE_NAME in 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 to serverName in 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_NAME is never set

Same with GRPC:

Also the way this is implemented is that if you omit serverName and don't have OTEL_SERVICE_NAME exported, but pass in a service name to NodeSDK, your fastify spans will get tagged with a service name of fastify as the fallback for serverName rather 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

Copy link
Member

@metcoder95 metcoder95 left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you add a tests that covers the NodeSDK path?

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I would like to understand more the issue here because it seems already handled to me

@bcomnes
Copy link
Contributor Author

bcomnes commented Jun 26, 2025

Can you add a tests that covers the NodeSDK path?

Yes, good idea. Will add something in.

@chiawendt chiawendt mentioned this pull request Aug 12, 2025
4 tasks
@chiawendt
Copy link
Contributor

I added a NodeSDK test in #86

@chiawendt
Copy link
Contributor

Hi @bcomnes thanks you for your effort, can you rebase this PR? This bug is causing our spans to have wrong service_name=fastify.

@bcomnes
Copy link
Contributor Author

bcomnes commented Sep 5, 2025

Yes I will today

@bcomnes
Copy link
Contributor Author

bcomnes commented Sep 5, 2025

There were some conflicts I tried to address. Hopefully the tests still pass.

# Conflicts:
#	index.js
#	test/index.test.js
@bcomnes
Copy link
Contributor Author

bcomnes commented Sep 6, 2025

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.

@bcomnes bcomnes requested review from Eomm and metcoder95 September 6, 2025 00:42
@bcomnes
Copy link
Contributor Author

bcomnes commented Sep 12, 2025

@Eomm Did these changes address your request? Sorry for the timeline on this one.

@Uzlopak Uzlopak requested a review from Copilot September 19, 2025 02:50
Copy link

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

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 })
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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).'); }

Suggested change
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).'
)
}

Copilot uses AI. Check for mistakes.

// Service name should be set via environment variable:
// export OTEL_SERVICE_NAME=my-server
// or via NodeSDK resource configuration
Copy link

Copilot AI Sep 19, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

[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.

Suggested change
// 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.

Copilot uses AI. Check for mistakes.
@bcomnes
Copy link
Contributor Author

bcomnes commented Sep 25, 2025

Ping @Eomm in case you might have time this week 😅

@chiawendt
Copy link
Contributor

Hi @gurgunday, can you help review this one?

@metcoder95 metcoder95 changed the title Don't set ATTR_SERVICE_NAME in fastify instrumentation feat: Don't set ATTR_SERVICE_NAME in fastify instrumentation Oct 2, 2025
Copy link
Member

@mcollina mcollina left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

lgtm

@mcollina
Copy link
Member

mcollina commented Oct 6, 2025

@bcomnes it's time to ship

@bcomnes
Copy link
Contributor Author

bcomnes commented Oct 6, 2025

I need someone to merge for me :)

Copy link
Member

@Eomm Eomm left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Sorry - I'm late 🙌

@bcomnes
Copy link
Contributor Author

bcomnes commented Oct 6, 2025

No worries thank you for reviewing!

@Eomm Eomm merged commit aff602a into fastify:main Oct 6, 2025
17 checks passed
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.

5 participants