-
Notifications
You must be signed in to change notification settings - Fork 227
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: span statistics -- ensure dropped span objects are still created #2694
Merged
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
b2edc03
feat: in progress
7a1cf0e
feat: remove logging
4d886b0
feat: make max span test fit
84fa951
fix: lint
f6a5afa
fix: lint
6736d5b
fix: lint
7169ef3
fix: correcting comment
e0825e5
replace hit-transaction-max-spans.js OTel Bridge test case with creat…
trentm e0e961c
fix lint and remove debugging printf
trentm f57cc51
test: fix running benchmarks (#2693)
trentm 0b15274
test: skip [email protected] in TAV tests to workaround npm v6 install iss…
trentm f6bb9e6
add traceContinuationStrategy config option; add Span Links API (#2692)
trentm 9261276
feat: add "nodejs16.x" lambda runtime to our compatible runtimes (#2697)
trentm 44e56dd
synchronize json schema specs (#2702)
apmmachine d31e33c
refactor: RunContext.exitSpan() -> .leaveSpan() (#2703)
trentm 3e76c3b
chore: deprecate 'hapi' package instrumentation (#2698)
trentm ac19339
chore(deps-dev): bump pug from 2.0.4 to 3.0.1 (#2690)
dependabot[bot] eec972b
synchronize json schema specs (#2704)
apmmachine 152df0c
fix: move isRecoded check
3e6c99e
Merge branch 'main' into astorm/span-stats-create-dropped-span
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 |
---|---|---|
|
@@ -186,10 +186,6 @@ Transaction.prototype.createSpan = function (...args) { | |
if (!this.sampled) { | ||
return null | ||
} | ||
if (this._builtSpans >= this._agent._conf.transactionMaxSpans) { | ||
this._droppedSpans++ | ||
return null | ||
} | ||
|
||
// Exit spans must not have child spans (unless of the same type and subtype). | ||
// https://github.com/elastic/apm/blob/master/specs/agents/tracing-spans.md#child-spans-of-exit-spans | ||
|
@@ -206,8 +202,15 @@ Transaction.prototype.createSpan = function (...args) { | |
return null | ||
} | ||
|
||
const span = new Span(this, ...args, opts) | ||
|
||
if (this._builtSpans >= this._agent._conf.transactionMaxSpans) { | ||
this._droppedSpans++ | ||
span.setRecorded(false) | ||
} | ||
|
||
this._builtSpans++ | ||
return new Span(this, ...args, opts) | ||
return span | ||
} | ||
|
||
// Note that this only returns a complete result when called *during* the call | ||
|
@@ -225,7 +228,7 @@ Transaction.prototype.toJSON = function () { | |
sampled: this.sampled, | ||
context: undefined, | ||
span_count: { | ||
started: this._builtSpans | ||
started: this._builtSpans - this._droppedSpans | ||
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. The |
||
}, | ||
outcome: this.outcome, | ||
faas: this._faas | ||
|
@@ -244,7 +247,6 @@ Transaction.prototype.toJSON = function () { | |
cloud: this._cloud || {}, | ||
message: this._message || {} | ||
} | ||
|
||
// Only include dropped count when spans have been dropped. | ||
if (this._droppedSpans > 0) { | ||
payload.span_count.dropped = this._droppedSpans | ||
|
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
81 changes: 81 additions & 0 deletions
81
test/opentelemetry-bridge/fixtures/createSpan-returns-null.js
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,81 @@ | ||
'use strict' | ||
|
||
// This tests the OTel Bridge for the case when `tracer.startSpan()` calls | ||
// the internal API `transaction.createSpan()` **and that returns null**. | ||
// Currently that can happen when attempting to create a child of an exit | ||
// span (a contrived case). | ||
// | ||
// The OTel Bridge needs to: | ||
// - return a non-recording span, because it needs to return something that | ||
// implements interface Span; and | ||
// - propagate W3C trace-context for possible subsequent outgoing HTTP requests | ||
// | ||
// Usage: | ||
// ELASTIC_APM_OPENTELEMETRY_BRIDGE_ENABLED=true \ | ||
// node -r ../../../start.js createSpan-returns-null.js | ||
// | ||
// Expected trace: | ||
// trace $traceId | ||
// `- transaction "aTrans" | ||
// `- span "anExitSpan" | ||
// `- transaction "GET unknown route" | ||
|
||
const apm = require('../../..') | ||
const assert = require('assert') | ||
const http = require('http') | ||
const otel = require('@opentelemetry/api') | ||
|
||
const tracer = otel.trace.getTracer('test-createSpan-returns-null') | ||
|
||
const server = http.createServer(function onRequest (req, res) { | ||
console.log('server request: %s %s %s', req.method, req.url, req.headers) | ||
req.resume() | ||
req.on('end', function () { | ||
const resBody = JSON.stringify({ ping: 'pong' }) | ||
res.writeHead(200, { | ||
'content-type': 'application/json', | ||
'content-length': Buffer.byteLength(resBody) | ||
}) | ||
res.end(resBody) | ||
}) | ||
}) | ||
|
||
async function makeAClientRequest (port) { | ||
return new Promise(resolve => { | ||
http.get({ | ||
host: 'localhost', | ||
port: port, | ||
path: '/ping' | ||
}, (cRes) => { | ||
console.log('client response status:', cRes.statusCode) | ||
console.log('client response headers:', cRes.headers) | ||
const body = [] | ||
cRes.on('data', (chunk) => body.push(chunk)) | ||
cRes.on('end', () => { | ||
console.log('client response body:', body.toString()) | ||
resolve() | ||
}) | ||
}) | ||
}) | ||
} | ||
|
||
server.listen(async () => { | ||
const port = server.address().port | ||
|
||
// 1. Create an APM transaction. | ||
tracer.startActiveSpan('aTrans', async (aTrans) => { | ||
// 2. Use the Elastic API to create an *exit* span. | ||
const anExitSpan = apm.startSpan('anExitSpan', 'myType', 'mySubtype', { exitSpan: true }) | ||
// 3. Attempt to create a child span of that exit span. This triggers the | ||
// code path where `Transaction#createSpan()` returns null. | ||
await tracer.startActiveSpan('theSpan', async (theSpan) => { | ||
assert.strictEqual(theSpan.isRecording(), false, 'theSpan is not recording') | ||
assert.strictEqual(theSpan.spanContext().spanId, anExitSpan.id, 'theSpan is carrying the trace-context of its parent (anExitSpan)') | ||
await makeAClientRequest(port) | ||
theSpan.end() | ||
}) | ||
anExitSpan.end() | ||
aTrans.end() | ||
server.close() | ||
}) | ||
}) |
79 changes: 0 additions & 79 deletions
79
test/opentelemetry-bridge/fixtures/hit-transaction-max-spans.js
This file was deleted.
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.
Note: The meaning of
_buildSpans
ends up changing slightly in this new world. The_buildSpans
property is always incremented regardless of whether a span will be dropped or not. To get the number of started spans we subtract the number of dropped spans from built spans (see below)