-
Notifications
You must be signed in to change notification settings - Fork 311
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(extension/opentelemetry): add new extension (#1081)
- Loading branch information
1 parent
24c1ae2
commit 84fe8be
Showing
31 changed files
with
854 additions
and
45 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import { inspect } from 'node:util' | ||
|
||
const originalWrite = globalThis.process.stdout.write.bind(globalThis.process.stdout) | ||
|
||
type Logger = typeof console.log | typeof globalThis.process.stdout.write | ||
|
||
export const show = <$Logger extends Logger = typeof console.log>( | ||
value: unknown, | ||
logger?: $Logger, | ||
): ReturnType<$Logger> => { | ||
const write = logger ?? console.log | ||
const inspected = inspect(value, { depth: null, colors: true }) | ||
const message = renderShow(inspected) | ||
return write(message) as ReturnType<$Logger> | ||
} | ||
|
||
export const showJson = <$Logger extends Logger = typeof console.log>( | ||
value: unknown, | ||
logger?: $Logger, | ||
): ReturnType<$Logger> => { | ||
const write = logger ?? console.log | ||
const encoded = JSON.stringify(value, null, 2) | ||
const message = renderShow(encoded) | ||
return write(message) as ReturnType<$Logger> | ||
} | ||
|
||
export const showPartition = `---------------------------------------- SHOW ----------------------------------------` | ||
|
||
const renderShow = (value: string) => { | ||
return showPartition + '\n' + value | ||
} | ||
|
||
export const interceptAndShowOutput = (): void => { | ||
globalThis.process.stdout.write = (value) => { | ||
if (typeof value !== `string`) return originalWrite(value) | ||
if (value.includes(showPartition)) return originalWrite(value) | ||
return originalWrite(renderShow(value)) | ||
} | ||
} |
10 changes: 10 additions & 0 deletions
10
examples/__outputs__/extension|extension_opentelemetry.output.encoder.ts
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,10 @@ | ||
export const encode = (value: string) => { | ||
return value | ||
.replaceAll(/(id: )'.+'/g, `$1'...'`) | ||
.replaceAll(/(traceId: )'.+'/g, `$1'...'`) | ||
.replaceAll(/(parentId: )'.+'/g, `$1'...'`) | ||
.replaceAll(/(timestamp: ).+,/g, `$10,`) | ||
.replaceAll(/(duration: ).+,/g, `$10.0,`) | ||
.replaceAll(/(service\.name': )'.+'/g, `$1'...'`) | ||
.replaceAll(/('telemetry\.sdk\.version': )'.+'/g, `$1'...'`) | ||
} |
156 changes: 156 additions & 0 deletions
156
examples/__outputs__/extension|extension_opentelemetry.output.test.txt
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,156 @@ | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': '...', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '...' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '...', | ||
parentId: '...', | ||
traceState: undefined, | ||
name: 'encode', | ||
id: '...', | ||
kind: 0, | ||
timestamp: 0, | ||
duration: 0.0, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': '...', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '...' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '...', | ||
parentId: '...', | ||
traceState: undefined, | ||
name: 'pack', | ||
id: '...', | ||
kind: 0, | ||
timestamp: 0, | ||
duration: 0.0, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': '...', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '...' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '...', | ||
parentId: '...', | ||
traceState: undefined, | ||
name: 'exchange', | ||
id: '...', | ||
kind: 0, | ||
timestamp: 0, | ||
duration: 0.0, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': '...', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '...' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '...', | ||
parentId: '...', | ||
traceState: undefined, | ||
name: 'unpack', | ||
id: '...', | ||
kind: 0, | ||
timestamp: 0, | ||
duration: 0.0, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': '...', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '...' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '...', | ||
parentId: '...', | ||
traceState: undefined, | ||
name: 'decode', | ||
id: '...', | ||
kind: 0, | ||
timestamp: 0, | ||
duration: 0.0, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': '...', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '...' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '...', | ||
parentId: undefined, | ||
traceState: undefined, | ||
name: 'request', | ||
id: '...', | ||
kind: 0, | ||
timestamp: 0, | ||
duration: 0.0, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
continents: [ | ||
{ name: 'Africa' }, | ||
{ name: 'Antarctica' }, | ||
{ name: 'Asia' }, | ||
{ name: 'Europe' }, | ||
{ name: 'North America' }, | ||
{ name: 'Oceania' }, | ||
{ name: 'South America' } | ||
] | ||
} |
156 changes: 156 additions & 0 deletions
156
examples/__outputs__/extension|extension_opentelemetry.output.txt
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,156 @@ | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '1.26.0' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '93ece70aa164958fd1b3d3c6c89e9f70', | ||
parentId: 'e3b3fd57f531674b', | ||
traceState: undefined, | ||
name: 'encode', | ||
id: '0f8e4e2d2fa7a1d1', | ||
kind: 0, | ||
timestamp: 1726068743834000, | ||
duration: 442.792, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '1.26.0' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '93ece70aa164958fd1b3d3c6c89e9f70', | ||
parentId: 'e3b3fd57f531674b', | ||
traceState: undefined, | ||
name: 'pack', | ||
id: '37766e2e0fa6ea2e', | ||
kind: 0, | ||
timestamp: 1726068743836000, | ||
duration: 808.5, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '1.26.0' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '93ece70aa164958fd1b3d3c6c89e9f70', | ||
parentId: 'e3b3fd57f531674b', | ||
traceState: undefined, | ||
name: 'exchange', | ||
id: 'ed9ae7aad6fd1e69', | ||
kind: 0, | ||
timestamp: 1726068743837000, | ||
duration: 329989.458, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '1.26.0' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '93ece70aa164958fd1b3d3c6c89e9f70', | ||
parentId: 'e3b3fd57f531674b', | ||
traceState: undefined, | ||
name: 'unpack', | ||
id: 'd0d9cbd74e358490', | ||
kind: 0, | ||
timestamp: 1726068744168000, | ||
duration: 1907.291, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '1.26.0' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '93ece70aa164958fd1b3d3c6c89e9f70', | ||
parentId: 'e3b3fd57f531674b', | ||
traceState: undefined, | ||
name: 'decode', | ||
id: '51a5859eae82dd62', | ||
kind: 0, | ||
timestamp: 1726068744170000, | ||
duration: 97.958, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
resource: { | ||
attributes: { | ||
'service.name': 'unknown_service:/Users/jasonkuhrt/Library/pnpm/nodejs/22.7.0/bin/node', | ||
'telemetry.sdk.language': 'nodejs', | ||
'telemetry.sdk.name': 'opentelemetry', | ||
'telemetry.sdk.version': '1.26.0' | ||
} | ||
}, | ||
instrumentationScope: { name: 'graffle', version: undefined, schemaUrl: undefined }, | ||
traceId: '93ece70aa164958fd1b3d3c6c89e9f70', | ||
parentId: undefined, | ||
traceState: undefined, | ||
name: 'request', | ||
id: 'e3b3fd57f531674b', | ||
kind: 0, | ||
timestamp: 1726068743834000, | ||
duration: 336135.125, | ||
attributes: {}, | ||
status: { code: 0 }, | ||
events: [], | ||
links: [] | ||
} | ||
---------------------------------------- SHOW ---------------------------------------- | ||
{ | ||
continents: [ | ||
{ name: 'Africa' }, | ||
{ name: 'Antarctica' }, | ||
{ name: 'Asia' }, | ||
{ name: 'Europe' }, | ||
{ name: 'North America' }, | ||
{ name: 'Oceania' }, | ||
{ name: 'South America' } | ||
] | ||
} |
Oops, something went wrong.