-
Notifications
You must be signed in to change notification settings - Fork 13
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: remove injection options (#312)
- Loading branch information
Showing
20 changed files
with
256 additions
and
134 deletions.
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
7 changes: 7 additions & 0 deletions
7
change/@splunk-otel-8acd8087-05ea-418e-9fa8-cd0cf4298f73.json
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 |
---|---|---|
@@ -0,0 +1,7 @@ | ||
{ | ||
"type": "major", | ||
"comment": "feat: remove logInjectionEnabled and SPLUNK_LOGS_INJECTION options", | ||
"packageName": "@splunk/otel", | ||
"email": "[email protected]", | ||
"dependentChangeType": "patch" | ||
} |
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 |
---|---|---|
@@ -0,0 +1,2 @@ | ||
node_modules | ||
package-lock.json |
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 |
---|---|---|
@@ -0,0 +1,30 @@ | ||
const { trace, SpanStatusCode, context } = require('@opentelemetry/api'); | ||
|
||
const log = require('pino')(); | ||
const doWork = () => { | ||
log.info('before work'); | ||
while (Date.now() - start < 500) {} | ||
log.info('after work work'); | ||
}; | ||
|
||
// There is no active span right now so no trace id to report. | ||
// Following log event will not have trace data injected. | ||
log.info('starting...'); | ||
|
||
const start = Date.now(); | ||
const tracer = trace.getTracer('splunk-otel-example-log-injection'); | ||
const span = tracer.startSpan('main'); | ||
const spanContext = trace.setSpan(context.active(), span); | ||
|
||
// This will run a function inside a context which has an active span. | ||
context.with(spanContext, doWork); | ||
|
||
// Even though the span has not ended yet it's not active in current context | ||
// anymore and thus will not be logged. | ||
log.info('done!'); | ||
span.end(); | ||
|
||
setTimeout(() => { | ||
// wait for the spans to be flushed | ||
console.log('Spans flushed'); | ||
}, 5000); |
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 |
---|---|---|
@@ -0,0 +1,27 @@ | ||
const { getInstrumentations } = require('@splunk/otel/lib/instrumentations'); | ||
const { defaultLogHook } = require('@splunk/otel/lib/instrumentations/logging'); | ||
const { PinoInstrumentation } = require('@opentelemetry/instrumentation-pino'); | ||
|
||
// an example logHook to add common resource attributes to every log message | ||
const logHook = (span, logRecord) => { | ||
// thrown errors in logHooks are ignored to avoid crashing due to instrumentation | ||
// logic. Deciding on using a try-catch comes down to the usecase and performance requirements. | ||
try { | ||
// defaultLogHook does the default behavior of adding service.[name, version] and deployment.environment | ||
// defaultLogHook(span, logRecord); // supported from 0.13 | ||
logRecord['my.attribute'] = 'my.value'; | ||
} catch (e) { | ||
console.error(e); | ||
throw e; | ||
} | ||
}; | ||
|
||
require('@splunk/otel').startTracing({ | ||
serviceName: 'example', | ||
instrumentations: [ | ||
...getInstrumentations(), | ||
new PinoInstrumentation({ | ||
logHook: logHook, | ||
}), | ||
], | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,16 @@ | ||
{ | ||
"name": "splunk-otel-example-log-injection", | ||
"private": true, | ||
"version": "1.0.0", | ||
"main": "index.js", | ||
"scripts": { | ||
"start": "node -r ./log-injection.tracer.js index.js", | ||
"basic": "node -r @splunk/otel/instrument index.js" | ||
}, | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.0.3", | ||
"@opentelemetry/instrumentation-pino": "^0.23.0", | ||
"@splunk/otel": "^0.12.0", | ||
"pino": "^6.13.3" | ||
} | ||
} |
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
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 |
---|---|---|
@@ -0,0 +1,8 @@ | ||
services: | ||
app: | ||
working_dir: /home/node/app/examples/log-injection | ||
env_file: ./log-injection/app.env | ||
test: | ||
command: node ./log-injection | ||
environment: | ||
COLLECTOR_URL: http://collector:8378 |
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 |
---|---|---|
@@ -0,0 +1,4 @@ | ||
OTEL_SERVICE_NAME='log-injection-example' | ||
OTEL_RESOURCE_ATTRIBUTES='deployment.environment=dev' | ||
OTEL_LOG_LEVEL='DEBUG' | ||
OTEL_EXPORTER_OTLP_ENDPOINT=http://collector:55681/v1/traces |
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 |
---|---|---|
@@ -0,0 +1,14 @@ | ||
const { | ||
assertSpans, | ||
logSpanTable, | ||
request, | ||
waitSpans, | ||
} = require('../utils.js'); | ||
const snapshot = require('./snapshot.js'); | ||
|
||
waitSpans(snapshot.length).then((data) => { | ||
logSpanTable(data); | ||
assertSpans(data, snapshot); | ||
}).then(() => { | ||
console.log(`${snapshot.length} span(s) validated.`); | ||
}); |
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 |
---|---|---|
@@ -0,0 +1,19 @@ | ||
// a console.log from a previous run | ||
module.exports = [ | ||
{ | ||
traceId: 'DUaJffuwfAqa53DY7yipHA==', | ||
id: 'QD8nT/PZGF8=', | ||
startTime: '2021-09-28T08:23:37.842474752Z', | ||
name: 'main', | ||
kind: 'internal', | ||
parentSpanId: undefined, | ||
parent: undefined, | ||
references: undefined, | ||
status: { code: undefined }, | ||
attributes: { | ||
'otel.library.name': 'splunk-otel-example-log-injection', | ||
'span.kind': 'internal', | ||
'status.code': undefined | ||
} | ||
} | ||
]; |
Oops, something went wrong.