-
Notifications
You must be signed in to change notification settings - Fork 931
feat: ESM support for instrumentation #3698
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
Merged
Merged
Changes from 39 commits
Commits
Show all changes
46 commits
Select commit
Hold shift + click to select a range
43fd59e
docs: add example for esm-http-ts
JamieDanielson e5215fe
fix: use instr version not node version
JamieDanielson 3c51c6d
deps: add import-in-the-middle
JamieDanielson 8444af3
feat: add iitm for esm instr
JamieDanielson e4478d9
docs: add readme notes from valentin
JamieDanielson 1434b27
wip: add test based on valentin's test
JamieDanielson a533f9f
remove changes to ritm init
JamieDanielson a43089b
update example - use build dir, add readme
JamieDanielson 85a2e8f
add changelog entry
JamieDanielson e0b5c44
dont use ritm singleton for iitm
JamieDanielson 63477c5
fix up call for new iitm
JamieDanielson 1188c02
Merge branch 'main' into esm-support
JamieDanielson 33e544c
Merge branch 'main' into esm-support
lizthegrey bfe51f5
wrap function refactor
pkanal 7110c37
clean up
pkanal 3ddb3a9
Merge pull request #1 from honeycombio/purvi/esm-tests
JamieDanielson 3f3d9a2
Merge branch 'main' into esm-support
JamieDanielson 2936a16
update changelog: it takes a village
JamieDanielson 4a10129
small cleanup on test
JamieDanielson 50363c5
version should be node version, not instr version
JamieDanielson c9922c3
run lint:fix for prettier error
JamieDanielson b722486
Merge pull request #2 from honeycombio/jamie.http-node-version
pkanal 4ac1ee1
base unwrap functionality
pkanal a346531
move esm specific wrap logic to node class
pkanal 1ca6b55
fix types
pkanal 4401576
add masswrap & massunwrap
pkanal 86b6837
handle edge cases for masswrap and massunwrap
pkanal da694c7
Merge pull request #3 from honeycombio/purvi.unwrap
JamieDanielson 1612855
Merge branch 'main' into esm-support
JamieDanielson e924c99
Ship shimmer types (#5)
pkanal b894bcd
Merge branch 'main' into esm-support
pkanal 68c43c9
use --experimental-meta-resolve option with hook file (#8)
pkanal a2a74f8
Merge branch 'main' into esm-support
pkanal a529c8c
fix markdown
pkanal ddc8dc5
Merge branch 'main' into esm-support
pkanal 42eb5ba
address PR feedback (#9)
pkanal 4f71df8
Update experimental/packages/opentelemetry-instrumentation/hook.js
pkanal 6a052b1
Update experimental/packages/opentelemetry-instrumentation/hook.mjs
pkanal 58d34c0
change back to process.versions.node (#10)
pkanal 33409da
address pr feedback (#11)
pkanal 1f017b0
remove `--experimental-import-meta-resolve` flag (#12)
pkanal 16109d3
Merge branch 'main' into esm-support
JamieDanielson bcaef1c
Merge branch 'main' into esm-support
JamieDanielson c590efc
Merge branch 'main' into esm-support
JamieDanielson 59047bd
remove import limitation from README
pkanal 0167a10
add esm example to examples readme
pkanal 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 hidden or 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,25 @@ | ||
# Overview | ||
|
||
This is a simple example that demonstrates tracing HTTP request, with an app written in TypeScript and transpiled to ES Modules. | ||
|
||
## Installation | ||
|
||
```sh | ||
# from this directory | ||
npm install | ||
npm run build | ||
npm start | ||
``` | ||
|
||
In a separate terminal, `curl localhost:3000`. | ||
|
||
See two spans in the console (one manual, one for http instrumentation) | ||
|
||
## Useful links | ||
|
||
- For more information on OpenTelemetry, visit: <https://opentelemetry.io/> | ||
- For more information on OpenTelemetry for Node.js, visit: <https://github.com/open-telemetry/opentelemetry-js/tree/main/packages/opentelemetry-sdk-trace-node> | ||
|
||
## LICENSE | ||
|
||
Apache License 2.0 |
This file contains hidden or 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,43 @@ | ||
import { registerInstrumentations } from '@opentelemetry/instrumentation'; | ||
import { trace, DiagConsoleLogger, DiagLogLevel, diag } from '@opentelemetry/api'; | ||
import { HttpInstrumentation } from '@opentelemetry/instrumentation-http'; | ||
import { NodeTracerProvider } from '@opentelemetry/sdk-trace-node'; | ||
import { | ||
ConsoleSpanExporter, | ||
SimpleSpanProcessor, | ||
} from '@opentelemetry/sdk-trace-base'; | ||
import { Resource } from '@opentelemetry/resources'; | ||
import { SemanticResourceAttributes } from '@opentelemetry/semantic-conventions'; | ||
import http from 'http'; | ||
Flarna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
diag.setLogger(new DiagConsoleLogger(), DiagLogLevel.DEBUG); | ||
const tracerProvider = new NodeTracerProvider({ | ||
resource: new Resource({ | ||
[SemanticResourceAttributes.SERVICE_NAME]: 'esm-http-ts-example', | ||
}), | ||
}); | ||
const exporter = new ConsoleSpanExporter(); | ||
const processor = new SimpleSpanProcessor(exporter); | ||
tracerProvider.addSpanProcessor(processor); | ||
tracerProvider.register(); | ||
|
||
registerInstrumentations({ | ||
instrumentations: [new HttpInstrumentation()], | ||
}); | ||
|
||
const hostname = '0.0.0.0'; | ||
const port = 3000; | ||
|
||
const server = http.createServer((req, res) => { | ||
res.statusCode = 200; | ||
res.setHeader('Content-Type', 'text/plain'); | ||
const tracer = trace.getTracer('esm-tracer'); | ||
tracer.startActiveSpan('manual', span => { | ||
span.end(); | ||
}); | ||
res.end('Hello, World!\n'); | ||
}); | ||
|
||
server.listen(port, hostname, () => { | ||
console.log(`Server running at http://${hostname}:${port}/`); | ||
}); |
This file contains hidden or 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,42 @@ | ||
{ | ||
"name": "esm-http-ts", | ||
"private": true, | ||
"version": "0.38.0", | ||
"description": "Example of HTTP integration with OpenTelemetry using ESM and TypeScript", | ||
"main": "build/index.js", | ||
"type": "module", | ||
"scripts": { | ||
"build": "tsc --build", | ||
"start": "node --experimental-import-meta-resolve --experimental-loader=@opentelemetry/instrumentation/hook.mjs ./build/index.js" | ||
}, | ||
"repository": { | ||
"type": "git", | ||
"url": "git+ssh://[email protected]/open-telemetry/opentelemetry-js.git" | ||
}, | ||
"keywords": [ | ||
"opentelemetry", | ||
"http", | ||
"tracing", | ||
"esm", | ||
"typescript" | ||
], | ||
"engines": { | ||
"node": ">=14" | ||
}, | ||
"author": "OpenTelemetry Authors", | ||
"license": "Apache-2.0", | ||
"bugs": { | ||
"url": "https://github.com/open-telemetry/opentelemetry-js/issues" | ||
}, | ||
"homepage": "https://github.com/open-telemetry/opentelemetry-js/tree/main/examples/", | ||
"dependencies": { | ||
"@opentelemetry/api": "^1.4.0", | ||
"@opentelemetry/exporter-trace-otlp-proto": "^0.36.0", | ||
Flarna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
"@opentelemetry/instrumentation": "0.38.0", | ||
"@opentelemetry/instrumentation-http": "0.38.0", | ||
"@opentelemetry/resources": "^1.9.1", | ||
"@opentelemetry/sdk-trace-base": "^1.9.1", | ||
"@opentelemetry/sdk-trace-node": "^1.9.1", | ||
"@opentelemetry/semantic-conventions": "^1.9.1" | ||
} | ||
} |
This file contains hidden or 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,25 @@ | ||
{ | ||
"compilerOptions": { | ||
/* Language and Environment */ | ||
"target": "ES2020" /* Set the JavaScript language version for emitted JavaScript and include compatible library declarations. */, | ||
Flarna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
|
||
/* Modules */ | ||
"module": "ESNext" /* Specify what module code is generated. */, | ||
"rootDir": "." /* Specify the root folder within your source files. */, | ||
"moduleResolution": "node" /* Specify how TypeScript looks up a file from a given module specifier. */, | ||
"resolveJsonModule": true /* Enable importing .json files. */, | ||
|
||
/* Emit */ | ||
"outDir": "build" /* Specify an output folder for all emitted files. */, | ||
|
||
/* Interop Constraints */ | ||
"allowSyntheticDefaultImports": true /* Allow 'import x from y' when a module doesn't have a default export. */, | ||
"esModuleInterop": true /* Emit additional JavaScript to ease support for importing CommonJS modules. This enables 'allowSyntheticDefaultImports' for type compatibility. */, | ||
"forceConsistentCasingInFileNames": true /* Ensure that casing is correct in imports. */, | ||
|
||
/* Completeness */ | ||
"skipLibCheck": true /* Skip type checking all .d.ts files. */ | ||
Flarna marked this conversation as resolved.
Show resolved
Hide resolved
|
||
}, | ||
"include": ["**/*.ts", "**/*.js", "*.config.js"], | ||
"exclude": ["node_modules"] | ||
} |
This file contains hidden or 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 hidden or 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 hidden or 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
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.
Uh oh!
There was an error while loading. Please reload this page.