-
Notifications
You must be signed in to change notification settings - Fork 13
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: remove injection options #312
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
745aae6
feat: add example for log injection
rauno56 b026bf0
feat: make assertInjection sync
rauno56 98fb42e
feat: test service name by default
rauno56 331826b
feat: make it possible to opt out form our logHook
rauno56 14eaaf3
refactor: rename `logHook` to `defaultLogHook`
rauno56 29ef508
style: fix lint
rauno56 68d1887
test: enable e2e logging log-injection example
rauno56 8a55bd1
feat(e2e): make sure the collector is up before running the app
rauno56 1b4c11b
feat: e2e test with log-injection example
rauno56 01e175d
feat: remove logInjectionEnabled option
rauno56 9d976d8
fix: remove unused arguments for options in log injection code
rauno56 cdecf55
style: lint fix
rauno56 e93ac23
chore: Add change files
rauno56 a4d2022
chore: remove change for e2e tests
rauno56 4d05a80
Merge branch 'main' into feat/remove-injection-options
rauno56 4b01149
style: move the default value to the signature
rauno56 fd0d29d
fix: use different test values in different tests
rauno56 54cf43a
docs: fix the wording about log injection in README
rauno56 88949e7
Merge branch 'feat/remove-injection-options' of github.com:Rauno56/sp…
rauno56 db2b32e
Merge remote-tracking branch 'upstream/main' into feat/remove-injecti…
rauno56 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
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.
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.
what about ForceFlush? spec implementation
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.
Our SDK currently doesn't provide access to the NodeTracerProvider we initialize.
#331
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.
What about using API to get the global one?
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.
That currently gives us ProxyTracerProvider, which doesn't have forceFlush either and has NTP under private property. I don't have a full understanding of the correct way to solve this situation and that's why I'd like to leave it for now and figure it out after the next release.