-
Notifications
You must be signed in to change notification settings - Fork 227
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: span statistics -- ensure dropped span objects are still created (
- Loading branch information
Showing
9 changed files
with
130 additions
and
146 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
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
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.