-
Notifications
You must be signed in to change notification settings - Fork 821
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(shim-opentracing): update logging based on new spec #2282
Merged
Merged
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
f891a4d
feat(shim-opentracing): update logging based on new spec
vreynolds dd9df52
chore: merge branch 'main' into ot-shim-log-updates
vreynolds 4b1ad09
Merge branch 'main' into ot-shim-log-updates
dyladan 8cc0ddd
chore: remove noop registration from example
vreynolds 6bd55df
Merge branch 'main' into ot-shim-log-updates
dyladan File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,33 +1,33 @@ | ||
'use strict'; | ||
|
||
const { registerInstrumentations } = require('@opentelemetry/instrumentation'); | ||
const { ResourceAttributes } = require('@opentelemetry/semantic-conventions'); | ||
const { Resource } = require('@opentelemetry/resources'); | ||
const { NodeTracerProvider } = require('@opentelemetry/node'); | ||
const { SimpleSpanProcessor } = require('@opentelemetry/tracing'); | ||
const { JaegerExporter } = require('@opentelemetry/exporter-jaeger'); | ||
const { ZipkinExporter } = require('@opentelemetry/exporter-zipkin'); | ||
const { TracerShim } = require('@opentelemetry/shim-opentracing'); | ||
|
||
function shim(serviceName) { | ||
const provider = new NodeTracerProvider(); | ||
const provider = new NodeTracerProvider({ | ||
resource: new Resource({ [ResourceAttributes.SERVICE_NAME]: serviceName }), | ||
}); | ||
|
||
provider.addSpanProcessor(new SimpleSpanProcessor(getExporter(serviceName))); | ||
// Initialize the OpenTelemetry APIs to use the NodeTracerProvider bindings | ||
provider.register(); | ||
|
||
registerInstrumentations({ | ||
}); | ||
|
||
return new TracerShim(provider.getTracer('opentracing-shim')); | ||
} | ||
|
||
function getExporter(serviceName) { | ||
function getExporter() { | ||
const type = process.env.EXPORTER.toLowerCase() || 'jaeger'; | ||
|
||
if (type.startsWith('z')) { | ||
return new ZipkinExporter({ serviceName }); | ||
return new ZipkinExporter(); | ||
} | ||
|
||
return new JaegerExporter({ serviceName, flushInterval: 100 }); | ||
return new JaegerExporter(); | ||
} | ||
|
||
exports.shim = shim; |
This file contains 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
This file contains 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
This file contains 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
This file contains 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
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.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
string
is the only "exception" type that's possible here, since the override method takesSpanAttributes
, meaning shim consumers can't log an attribute likeerror.object: new Error()
, if they're using type safetyThere was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do you mean the error type from our api or from opentracing conventions ? Because i believe we handle error object too ?
https://github.com/open-telemetry/opentelemetry-js/blob/main/packages/opentelemetry-tracing/src/Span.ts#L189
https://github.com/open-telemetry/opentelemetry-js-api/blob/41109c83a9784d689f319f2c5d953b3874c694a3/src/common/Exception.ts#L43
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
You are correct,
recordException
can take an Error object, but the log function itself takesSpanAttributes
which don't allow objects as attribute values:opentelemetry-js/packages/opentelemetry-shim-opentracing/src/shim.ts
Line 291 in a3b7738
The issue here is that the shim restricts the types more than the OpenTracing lib: https://github.com/opentracing/opentracing-javascript/blob/111ea4f7939c8f8f538333330d72115e5b28bcce/src/span.ts#L143 where you can pass
any
as attribute values, including objects.