Open
Conversation
Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
- Add src/utils/tracing.ts with initializeTracing(), shutdownTracing(), getTracer(), and withToolSpan() — consistent with mcp-server and mcp-devkit-server - BaseTool.run() wraps every execution in a tool.<name> span via withToolSpan(); sets tool.error=true attribute on tool-level errors - index.ts initializes tracing on startup and shuts it down on graceful exit - OTEL is a no-op unless OTEL_EXPORTER_OTLP_ENDPOINT or OTEL_EXPORTER_CONSOLE_ENABLED=true is set; diagnostics suppressed on stdio - Export tracing utilities from @mapbox/mcp-docs-server/utils barrel - Add OTEL 2.x dependencies: api@^1.9.1, resources@^2.6.1, sdk-trace-base@^2.6.1, sdk-node@^0.214.0, instrumentation@^0.214.0, exporter-trace-otlp-http@^0.214.0, auto-instrumentations-node@^0.72.0, semantic-conventions@^1.40.0 Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
zmofei
approved these changes
Apr 15, 2026
Member
zmofei
left a comment
There was a problem hiding this comment.
LGTM! Clean implementation, consistent with sibling repos. One minor issue:
src/tools/BaseTool.ts — missing tool.error attribute in catch block
The try path sets span.setAttribute('tool.error', true) when result.isError, but the catch path (which also returns isError: true) doesn't set it. Since the inner catch returns rather than re-throws, withToolSpan sees a successful completion and marks the span SpanStatusCode.OK.
Validation failures and unexpected exceptions will produce spans that look successful — no tool.error attribute, status OK.
Suggested fix:
} catch (error) {
span.setAttribute('tool.error', true);
return {
isError: true,
content: [{ type: 'text', text: (error as Error).message }]
};
}Not blocking — can be a follow-up.
4 tasks
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Adds OpenTelemetry tracing to
mcp-docs-server, consistent with the implementation inmcp-serverandmcp-devkit-server.src/utils/tracing.ts(new) —initializeTracing(),shutdownTracing(),getTracer(), andwithToolSpan(). Suppresses OTEL diagnostic output at module load time to protect MCP stdio.BaseTool.run()— wraps every tool execution in atool.<name>span viawithToolSpan(); setstool.error=trueattribute when a tool returnsisError: true.src/index.ts— callsinitializeTracing()on startup,shutdownTracing()on graceful exit.src/utils/index.ts— exports tracing utilities from@mapbox/mcp-docs-server/utils.Tracing is a no-op by default. It activates only when
OTEL_EXPORTER_OTLP_ENDPOINTorOTEL_EXPORTER_CONSOLE_ENABLED=trueis set. Uses OTEL 2.x (resourceFromAttributesinstead of the removedResourceclass).Test plan
npm run buildpassesnpm test— 58 tests pass (tracing is no-op in test env viaVITESTguard)🤖 Generated with Claude Code