-
Notifications
You must be signed in to change notification settings - Fork 7
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(js): Add Lightstep Adapter (#84)
* feat(js): Honeycomb adapter * feat: abstract interval logic in Adapter, modify OTEL payload to parse correctly * feat: abstract interval logic in Adapter, modify OTEL payload to parse correctly * fix(js): use nanosecond scale for timing. fix parentId assignment * fix(js): Use nanoseconds for timing metrics in collector * fix(js): demangle multi-initialization issue, handling multiple traces * fix(js): demangle multi-initialization issue, handling multiple traces * chore: update types and remove build artifacts from web test * feat(js): Add Lightstep adapter * feat(js): Add Lightstep adapter * fix: naming conventions, tests * fix: remove unnecessary deletion of traceId
- Loading branch information
Showing
18 changed files
with
382 additions
and
4 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
Binary file not shown.
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 @@ | ||
export { | ||
LightstepAdapter, | ||
LightstepConfig, | ||
} from '../../src/lib/adapters/lightstep/mod.js'; |
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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,40 @@ | ||
{ | ||
"name": "@dylibso/observe-sdk-lightstep", | ||
"version": "1.0.0", | ||
"description": "A library that produces function tracing to lightstep", | ||
"directories": { | ||
"test": "test" | ||
}, | ||
"main": "./dist/cjs/index.js", | ||
"module": "./dist/esm/index.js", | ||
"types": "./dist/types/index.d.ts", | ||
"exports": { | ||
".": { | ||
"types": "./dist/types/index.d.ts", | ||
"require": "./dist/cjs/index.js", | ||
"default": "./dist/esm/index.js" | ||
} | ||
}, | ||
"scripts": { | ||
"build:esm": "node ../../esbuild/esbuild.js -b -e ./index.js -o ../observe-sdk-lightstep/dist/esm/index.js -p browser -f esm", | ||
"build:cjs": "node ../../esbuild/esbuild.js -b -e ./index.js -o ../observe-sdk-lightstep/dist/cjs/index.js -p browser -f cjs", | ||
"build:types": "tsc -b", | ||
"build": "npm run build:esm && npm run build:cjs && npm run build:types", | ||
"build:web-test": "node ../../esbuild/esbuild.js -b -e ./test/web/index.js -o ./test/web/build.js -p browser", | ||
"test:node": "node test/node/index.js", | ||
"test:deno": "deno run -A test/deno/index.ts", | ||
"test:web": "npm run build:web-test && npx serve ./test/web" | ||
}, | ||
"keywords": [ | ||
"dylibso", | ||
"lightstep", | ||
"tracing", | ||
"observe", | ||
"opentelemetry", | ||
"otel", | ||
"wasm", | ||
"webassembly" | ||
], | ||
"author": "", | ||
"license": "ISC" | ||
} |
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,36 @@ | ||
import { LightstepAdapter, LightstepConfig } from "../../dist/esm/index.js"; | ||
import Context from "https://deno.land/[email protected]/wasi/snapshot_preview1.ts"; | ||
import { load } from "https://deno.land/std/dotenv/mod.ts"; | ||
|
||
const env = await load(); | ||
const apiKey = env["LIGHTSTEP_API_KEY"]; | ||
|
||
const config: LightstepConfig = { | ||
apiKey: apiKey, | ||
serviceName: 'deno', | ||
emitTracesInterval: 1000, | ||
traceBatchMax: 100, | ||
host: 'https://ingest.lightstep.com', | ||
} | ||
const adapter = new LightstepAdapter(config); | ||
|
||
const bytes = await Deno.readFile("../../test-data/test.c.instr.wasm"); | ||
const traceContext = await adapter.start(bytes); | ||
const module = new WebAssembly.Module(bytes); | ||
|
||
const runtime = new Context({ | ||
stdin: Deno.stdin.rid, | ||
stdout: Deno.stdout.rid, | ||
}); | ||
const instance = new WebAssembly.Instance( | ||
module, | ||
{ | ||
"wasi_snapshot_preview1": runtime.exports, | ||
...traceContext.getImportObject(), | ||
}, | ||
); | ||
runtime.start(instance); | ||
|
||
traceContext.stop(); | ||
|
||
setTimeout(() => { }, 3000); |
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,37 @@ | ||
const fs = require("fs"); | ||
const { WASI } = require("wasi"); | ||
const { env, argv } = require('node:process'); | ||
const { LightstepAdapter } = require("@dylibso/observe-sdk-lightstep"); | ||
require('dotenv').config(); | ||
|
||
const wasi = new WASI({ | ||
version: "preview1", | ||
args: argv.slice(1), | ||
env, | ||
}); | ||
|
||
const config = { | ||
apiKey: process.env.LIGHTSTEP_API_KEY, | ||
serviceName: 'node', | ||
emitTracesInterval: 1000, | ||
traceBatchMax: 100, | ||
host: 'https://ingest.lightstep.com', | ||
} | ||
const adapter = new LightstepAdapter(config); | ||
|
||
const bytes = fs.readFileSync("../../test-data/test.c.instr.wasm"); | ||
adapter.start(bytes).then((traceContext) => { | ||
const module = new WebAssembly.Module(bytes); | ||
|
||
WebAssembly.instantiate(module, { | ||
...wasi.getImportObject(), | ||
...traceContext.getImportObject(), | ||
}).then((instance) => { | ||
wasi.start(instance); | ||
// adapter.setMetadata({ | ||
// http_status_code: 200, | ||
// http_url: "https://example.com", | ||
// }); | ||
traceContext.stop(); | ||
}); | ||
}); |
33 changes: 33 additions & 0 deletions
33
js/packages/observe-sdk-lightstep/test/node/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ | ||
"name": "test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"dotenv": "^16.3.1" | ||
} | ||
} |
Binary file not shown.
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,13 @@ | ||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<script src="./build.js"></script> | ||
</head> | ||
|
||
<body> | ||
|
||
</body> | ||
|
||
</html> |
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 { LightstepAdapter } from "@dylibso/observe-sdk-lightstep"; | ||
import { File, OpenFile, WASI } from "@bjorn3/browser_wasi_shim"; | ||
|
||
const f = async () => { | ||
const config = { | ||
apiKey: 'YOUR_API_KEY_HERE', | ||
serviceName: 'web', | ||
emitTracesInterval: 1000, | ||
traceBatchMax: 100, | ||
host: 'https://ingest.lightstep.com', | ||
} | ||
const adapter = new LightstepAdapter(config); | ||
const resp = await fetch("test.c.instr.wasm"); | ||
|
||
const bytes = await resp.arrayBuffer(); | ||
const traceContext = await adapter.start(bytes); | ||
|
||
let fds = [ | ||
new OpenFile( | ||
new File( | ||
new TextEncoder("utf-8").encode(`count these vowels for me please`), | ||
), | ||
), // stdin | ||
new OpenFile(new File([])), // stdout | ||
new OpenFile(new File([])), // stderr | ||
]; | ||
let wasi = new WASI([], [], fds); | ||
const instance = await WebAssembly.instantiate(bytes, { | ||
"wasi_snapshot_preview1": wasi.wasiImport, | ||
...traceContext.getImportObject(), | ||
}); | ||
|
||
wasi.start(instance.instance); | ||
let utf8decoder = new TextDecoder(); | ||
console.log(utf8decoder.decode(fds[1].file.data)); | ||
traceContext.stop(); | ||
}; | ||
|
||
f().then(() => { }); |
33 changes: 33 additions & 0 deletions
33
js/packages/observe-sdk-lightstep/test/web/package-lock.json
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
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 @@ | ||
{ | ||
"name": "test", | ||
"version": "1.0.0", | ||
"description": "", | ||
"main": "index.js", | ||
"scripts": { | ||
"test": "echo \"Error: no test specified\" && exit 1" | ||
}, | ||
"author": "", | ||
"license": "ISC", | ||
"dependencies": { | ||
"dotenv": "^16.3.1" | ||
} | ||
} |
Binary file not shown.
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,18 @@ | ||
{ | ||
"include": [ | ||
"index.ts", | ||
], | ||
"compilerOptions": { | ||
"allowJs": true, | ||
"declaration": true, | ||
"emitDeclarationOnly": true, | ||
"outDir": "dist/types", | ||
"outFile": "dist/types/index.d.ts", | ||
"declarationMap": true, | ||
"allowImportingTsExtensions": true, | ||
"lib": [ | ||
"DOM", | ||
"ESNext", | ||
] | ||
} | ||
} |
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
Oops, something went wrong.