-
Notifications
You must be signed in to change notification settings - Fork 10
feat(trace): allow environment variables usage for url and serviceName #19
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
base: master
Are you sure you want to change the base?
Changes from 10 commits
f952f02
4a13540
4d981c7
c20bfa1
0355467
41e8597
a78fc7f
cbea721
dba9355
41f3ba9
b915334
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -31,8 +31,8 @@ | |
value: '', | ||
}, | ||
url: { | ||
value: 'http://localhost:4318/v1/traces', | ||
required: true, | ||
value: '', | ||
required: false, | ||
validate: function (v) { | ||
try { | ||
// eslint-disable-next-line no-new | ||
|
@@ -44,8 +44,8 @@ | |
}, | ||
}, | ||
serviceName: { | ||
value: 'Node-RED', | ||
required: true, | ||
value: '', | ||
required: false, | ||
|
||
}, | ||
protocol: { | ||
value: 'http', | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
const os = require('os') | ||
const { name, version } = require('../package.json') | ||
const { trace, context, propagation, SpanKind, SpanStatusCode } = require('@opentelemetry/api') | ||
const { Resource } = require('@opentelemetry/resources') | ||
const { Resource, detectResourcesSync, envDetectorSync } = require('@opentelemetry/resources') | ||
const { ATTR_SERVICE_NAME, ATTR_HTTP_RESPONSE_STATUS_CODE, ATTR_URL_PATH, ATTR_SERVER_ADDRESS, ATTR_SERVER_PORT, ATTR_URL_SCHEME, ATTR_HTTP_REQUEST_METHOD, ATTR_CLIENT_ADDRESS, ATTR_USER_AGENT_ORIGINAL, ATTR_HTTP_REQUEST_HEADER } = require('@opentelemetry/semantic-conventions') | ||
// eslint-disable-next-line node/no-missing-require | ||
const { ATTR_HOST_NAME, ATTR_CODE_FUNCTION } = require('@opentelemetry/semantic-conventions/incubating') | ||
|
@@ -12,6 +12,7 @@ const { | |
CompositePropagator, | ||
W3CBaggagePropagator, | ||
W3CTraceContextPropagator, | ||
merge, | ||
|
||
} = require('@opentelemetry/core') | ||
const { clearInterval } = require('timers') | ||
const { defaultTextMapGetter } = require('@opentelemetry/api') | ||
|
@@ -249,7 +250,6 @@ function createSpan (tracer, msg, nodeDefinition, node, isNotTraced) { | |
parentSpan = tracer.startSpan(_rootPrefix + spanName, { | ||
attributes: { | ||
[ATTR_IS_MESSAGE_CREATION]: true, | ||
[ATTR_SERVICE_NAME]: nodeDefinition.type, | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I prefer to keep the There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. When I tested it it was just set to I can make it as another config option which is turned on by default, what do you think? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. For my understanding, you have a service name for each Node-RED instance? |
||
...commonAttributes, | ||
}, | ||
kind, | ||
|
@@ -478,26 +478,35 @@ module.exports = function (RED) { | |
_attributeMappings = attributeMappings | ||
|
||
// check config | ||
if (!url) { | ||
this.status({ fill: 'red', shape: 'ring', text: 'invalid configuration' }) | ||
return | ||
} | ||
const node = this | ||
|
||
// create tracer | ||
let spanProcessor | ||
const traceExporterProps = url ? { url } : {} | ||
|
||
if (protocol === 'proto') { | ||
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-proto') | ||
spanProcessor = new BatchSpanProcessor(new OTLPTraceExporter({ url })) | ||
spanProcessor = new BatchSpanProcessor(new OTLPTraceExporter(traceExporterProps)) | ||
} else { | ||
const { OTLPTraceExporter } = require('@opentelemetry/exporter-trace-otlp-http') | ||
spanProcessor = new BatchSpanProcessor(new OTLPTraceExporter({ url })) | ||
spanProcessor = new BatchSpanProcessor(new OTLPTraceExporter(traceExporterProps)) | ||
} | ||
|
||
// Create OTEL resource, combining props passed via environment variables | ||
// and those explicitly given in OTEL node UI | ||
const explicitResource = new Resource( | ||
serviceName | ||
? { [ATTR_SERVICE_NAME]: serviceName, [ATTR_HOST_NAME]: os.hostname() } | ||
: { [ATTR_HOST_NAME]: os.hostname() }, | ||
) | ||
const envResource = detectResourcesSync({ detectors: [envDetectorSync] }) | ||
const mergedResource = explicitResource.merge(envResource) | ||
|
||
if (_isLogging) { | ||
console.log('Initializing tracer provider with resource', mergedResource) | ||
} | ||
|
||
const provider = new BasicTracerProvider({ | ||
resource: new Resource({ | ||
[ATTR_SERVICE_NAME]: serviceName, | ||
[ATTR_HOST_NAME]: os.hostname(), | ||
}), | ||
resource: mergedResource, | ||
spanProcessors: [spanProcessor], | ||
}) | ||
provider.register() | ||
|
Uh oh!
There was an error while loading. Please reload this page.