@photon-ai/otel 0.1.2 → 1.1.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +68 -8
- package/dist/index.d.ts +60 -4
- package/dist/index.js +350 -62
- package/dist/index.js.map +1 -1
- package/package.json +4 -2
package/README.md
CHANGED
|
@@ -5,8 +5,9 @@ A DX-focused OpenTelemetry wrapper for **Bun** and **Node.js**.
|
|
|
5
5
|
Vanilla OTel works, but the setup is verbose, the logger plumbing is awkward, and PII scrubbing is on you. `@photon-ai/otel` wraps the OTLP/HTTP stack into a few well-named functions:
|
|
6
6
|
|
|
7
7
|
- **`setupOtel()`** — idempotent one-call bootstrap for traces + logs. Honors all standard `OTEL_EXPORTER_OTLP_*` env vars.
|
|
8
|
-
- **`createLogger(module)`** — structured logger that writes to both the OTel logger provider and `console`, with automatic trace correlation and exception capture.
|
|
8
|
+
- **`createLogger(module)`** — structured logger that writes to both the OTel logger provider and `console`, with automatic trace correlation and exception capture. Every level (`debug`/`info`/`warn`/`error`) accepts `attrs` **and** an `error`, and is gated by a configurable `LOG_LEVEL`.
|
|
9
9
|
- **`withSpan(name, attrs?, fn)`** — wrap any sync or async function in a span; errors are recorded and PII in the error message is scrubbed before being attached to span status.
|
|
10
|
+
- **Automatic `fetch` tracing** — `setupOtel()` wraps `globalThis.fetch` so every outbound request gets a CLIENT span and W3C trace-context headers. On **Bun** this is the only fetch instrumentation that works — the standard `diagnostics_channel`-based OTel instrumentations emit nothing for Bun's native fetch — and it behaves identically on Node.
|
|
10
11
|
- **`sanitizeEmail` / `sanitizePhone` / `sanitizeErrorMessage`** — PII helpers you can reuse anywhere.
|
|
11
12
|
|
|
12
13
|
OTLP/HTTP only (no gRPC, no proto). Works identically on Bun and Node ≥ 20.
|
|
@@ -34,7 +35,9 @@ const log = createLogger("server");
|
|
|
34
35
|
|
|
35
36
|
await withSpan("handle-request", { route: "/users" }, async () => {
|
|
36
37
|
log.info("processing request", { userId: 42 });
|
|
37
|
-
//
|
|
38
|
+
// Outbound fetch is traced automatically: a CLIENT span, parented to this
|
|
39
|
+
// one, with a `traceparent` header injected for the downstream service.
|
|
40
|
+
await fetch("https://api.example.com/users");
|
|
38
41
|
});
|
|
39
42
|
```
|
|
40
43
|
|
|
@@ -46,7 +49,10 @@ If `OTEL_EXPORTER_OTLP_ENDPOINT` (or the `endpoint` option) is unset, `setupOtel
|
|
|
46
49
|
| --------------------------------------------- | ---------------------------------------------------------------------------------------------------------- |
|
|
47
50
|
| `setupOtel(options): OtelHandle` | Boots OTLP/HTTP traces + logs. Idempotent. Returns `{ shutdown(): Promise<void> }`. |
|
|
48
51
|
| `isOtelActive(): boolean` | Returns `true` if `setupOtel` has already run in this process. |
|
|
52
|
+
| `instrumentFetch(options?): FetchInstrumentation` | Wraps `globalThis.fetch` for CLIENT spans + W3C propagation. Auto-enabled by `setupOtel` when traces are configured. Returns `{ unpatch() }`. |
|
|
49
53
|
| `createLogger(module): PhotonLogger` | Returns `{ info, warn, error, debug }`. Each call emits to OTel + `console`, correlates to active span. |
|
|
54
|
+
| `setLogLevel(level): void` | Set the minimum level emitted (`debug`/`info`/`warn`/`error`/`silent`). `LOG_LEVEL` env still wins. |
|
|
55
|
+
| `getLogLevel(): LogLevel` | Current effective level after env / override / default resolution. |
|
|
50
56
|
| `withSpan(name, fn)` | Wraps `fn` (sync or async) in a span. Records exceptions and scrubs PII in error messages. |
|
|
51
57
|
| `withSpan(name, attrs, fn)` | Same as above but attaches `attrs` to the span. |
|
|
52
58
|
| `sanitizeEmail(input)` | Masks an email: `foo.bar@example.com` → `fo***@e***.com`. |
|
|
@@ -57,13 +63,42 @@ If `OTEL_EXPORTER_OTLP_ENDPOINT` (or the `endpoint` option) is unset, `setupOtel
|
|
|
57
63
|
### Logger signatures
|
|
58
64
|
|
|
59
65
|
```ts
|
|
60
|
-
log.
|
|
61
|
-
log.
|
|
62
|
-
log.
|
|
63
|
-
log.
|
|
66
|
+
log.debug(message, attrs?, error?);
|
|
67
|
+
log.info(message, attrs?, error?);
|
|
68
|
+
log.warn(message, attrs?, error?); // attach the exception that caused a retry
|
|
69
|
+
log.error(message, attrs?, error?);
|
|
64
70
|
```
|
|
65
71
|
|
|
66
|
-
|
|
72
|
+
Every level takes the same `(message, attrs?, error?)` shape — attach an exception to a
|
|
73
|
+
`warn`/`info`/`debug`, not just `error`. `attrs` is
|
|
74
|
+
`Record<string, string | number | boolean | undefined>`; `undefined` values are dropped.
|
|
75
|
+
|
|
76
|
+
An `Error` is recorded as `exception.type` / `exception.message` / `exception.stacktrace`
|
|
77
|
+
on the OTLP record (per the OTel exception semantic convention); a non-`Error` throw is
|
|
78
|
+
coerced so at least `exception.message` is preserved.
|
|
79
|
+
|
|
80
|
+
Each call also prints a single human-readable console line — `[module] LEVEL message
|
|
81
|
+
{ ...attrs }` plus the raw error (so the runtime renders the full stack) — routed to
|
|
82
|
+
`console.debug` / `console.info` / `console.warn` / `console.error` by severity. Both
|
|
83
|
+
sinks share one level gate.
|
|
84
|
+
|
|
85
|
+
### Log level
|
|
86
|
+
|
|
87
|
+
Logs below the active level are dropped from **both** OTLP and the console. The level is
|
|
88
|
+
resolved fresh on every call, so changes take effect immediately:
|
|
89
|
+
|
|
90
|
+
1. `LOG_LEVEL` env var (`debug` | `info` | `warn` | `error` | `silent`) — wins if set.
|
|
91
|
+
2. `setLogLevel(level)` or `setupOtel({ logLevel })`.
|
|
92
|
+
3. Default: `debug` in development (`DEPLOYMENT_ENV` unset or `development`), `info` otherwise.
|
|
93
|
+
|
|
94
|
+
```ts
|
|
95
|
+
import { setLogLevel } from "@photon-ai/otel";
|
|
96
|
+
|
|
97
|
+
setLogLevel("warn"); // debug + info now suppressed everywhere
|
|
98
|
+
// or set LOG_LEVEL=warn in the environment, which overrides the call above
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`"silent"` suppresses everything, including errors.
|
|
67
102
|
|
|
68
103
|
## Configuration
|
|
69
104
|
|
|
@@ -75,7 +110,32 @@ Standard OpenTelemetry env vars always take precedence over `SetupOtelOptions`:
|
|
|
75
110
|
| `OTEL_EXPORTER_OTLP_TRACES_ENDPOINT` | Full traces URL (overrides the base for traces). |
|
|
76
111
|
| `OTEL_EXPORTER_OTLP_LOGS_ENDPOINT` | Full logs URL (overrides the base for logs). |
|
|
77
112
|
| `OTEL_EXPORTER_OTLP_HEADERS` | `key=value,key=value` headers; merged with `options.headers` (env wins). |
|
|
78
|
-
| `DEPLOYMENT_ENV` | Attached as `deployment.environment` resource attribute. Defaults to `development`. |
|
|
113
|
+
| `DEPLOYMENT_ENV` | Attached as `deployment.environment` resource attribute. Defaults to `development`. Also drives the default log level. |
|
|
114
|
+
| `LOG_LEVEL` | Minimum log level: `debug` \| `info` \| `warn` \| `error` \| `silent`. Overrides `setLogLevel()` / `setupOtel({ logLevel })`. |
|
|
115
|
+
|
|
116
|
+
## Automatic fetch instrumentation
|
|
117
|
+
|
|
118
|
+
`setupOtel()` patches `globalThis.fetch` to emit a CLIENT span per outbound request, carrying
|
|
119
|
+
W3C `traceparent` (and baggage) headers so traces continue across services. Each span is named by
|
|
120
|
+
HTTP method (`GET`, `POST`, …) and carries `http.request.method`, `url.full`, `server.address`,
|
|
121
|
+
`server.port`, and `http.response.status_code`; `4xx`/`5xx` responses and thrown network errors are
|
|
122
|
+
marked `ERROR`. This covers **outbound** requests only — inbound `Bun.serve`/Elysia server spans are
|
|
123
|
+
separate (see [Framework integration](#framework-integration)).
|
|
124
|
+
|
|
125
|
+
- **Default:** on when a traces endpoint is configured. Pass `instrumentFetch: false` to disable, or
|
|
126
|
+
`instrumentFetch: true` to force it on even without an endpoint.
|
|
127
|
+
- **Filter URLs:** `instrumentFetch: { ignore: (url) => url.includes("/healthz") }`. Your own OTLP
|
|
128
|
+
endpoint is always excluded automatically, so the exporter never traces itself.
|
|
129
|
+
- **Why Bun needs this:** Bun's native `fetch` emits no `diagnostics_channel` events, so
|
|
130
|
+
`@opentelemetry/instrumentation-undici` / `-http` — and `opentelemetry-instrumentation-fetch-node`,
|
|
131
|
+
which is itself `diagnostics_channel`-based — produce no spans. Wrapping the global is the only
|
|
132
|
+
mechanism that works, and it behaves identically on Node.
|
|
133
|
+
- **Caveat:** `url.full` includes the query string. If your URLs carry secrets there, use `ignore`
|
|
134
|
+
or redact upstream.
|
|
135
|
+
|
|
136
|
+
`setupOtel()` also installs a global W3C trace-context + baggage propagator (previously none was
|
|
137
|
+
registered) — that is what makes the outbound `traceparent` injection, and any manual propagation,
|
|
138
|
+
actually take effect.
|
|
79
139
|
|
|
80
140
|
## Running on Node vs Bun
|
|
81
141
|
|
package/dist/index.d.ts
CHANGED
|
@@ -1,9 +1,48 @@
|
|
|
1
|
+
interface InstrumentFetchOptions {
|
|
2
|
+
/**
|
|
3
|
+
* Return `true` to skip instrumenting a request whose absolute URL is passed
|
|
4
|
+
* in. Useful to drop noisy endpoints or URLs that carry secrets in their
|
|
5
|
+
* query string. The request is still performed — only the span is skipped.
|
|
6
|
+
*/
|
|
7
|
+
ignore?: (url: string) => boolean;
|
|
8
|
+
}
|
|
9
|
+
interface FetchInstrumentation {
|
|
10
|
+
/** Restore the original `globalThis.fetch`. Safe to call more than once. */
|
|
11
|
+
unpatch(): void;
|
|
12
|
+
}
|
|
13
|
+
/**
|
|
14
|
+
* Wrap `globalThis.fetch` so every outbound request produces a CLIENT span and
|
|
15
|
+
* carries W3C trace context to the downstream service.
|
|
16
|
+
*
|
|
17
|
+
* On Bun this is the only fetch instrumentation that works: Bun's native fetch
|
|
18
|
+
* emits no `diagnostics_channel` events, so the standard `instrumentation-undici`
|
|
19
|
+
* / `instrumentation-http` (and `opentelemetry-instrumentation-fetch-node`,
|
|
20
|
+
* which is itself diagnostics_channel-based) produce no spans. It works
|
|
21
|
+
* identically on Node, where `globalThis.fetch` is undici-backed.
|
|
22
|
+
*
|
|
23
|
+
* Idempotent: a second call does not stack another wrapper. Returns a handle
|
|
24
|
+
* whose `unpatch()` restores the original fetch.
|
|
25
|
+
*/
|
|
26
|
+
declare function instrumentFetch(options?: InstrumentFetchOptions): FetchInstrumentation;
|
|
27
|
+
|
|
1
28
|
type LogAttrs = Record<string, string | number | boolean | undefined>;
|
|
29
|
+
/**
|
|
30
|
+
* Minimum severity that gets emitted (to both the OTLP record and the console).
|
|
31
|
+
* `"silent"` suppresses everything, including errors.
|
|
32
|
+
*/
|
|
33
|
+
type LogLevel = "debug" | "info" | "warn" | "error" | "silent";
|
|
34
|
+
/**
|
|
35
|
+
* Programmatically set the minimum log level. Takes effect immediately for
|
|
36
|
+
* subsequent logs. `LOG_LEVEL` env var still wins if set.
|
|
37
|
+
*/
|
|
38
|
+
declare function setLogLevel(level: LogLevel): void;
|
|
39
|
+
/** Current effective log level, after env / override / default resolution. */
|
|
40
|
+
declare function getLogLevel(): LogLevel;
|
|
2
41
|
interface PhotonLogger {
|
|
3
|
-
debug(message: string, attrs?: LogAttrs): void;
|
|
42
|
+
debug(message: string, attrs?: LogAttrs, error?: unknown): void;
|
|
4
43
|
error(message: string, attrs?: LogAttrs, error?: unknown): void;
|
|
5
|
-
info(message: string, attrs?: LogAttrs): void;
|
|
6
|
-
warn(message: string, attrs?: LogAttrs): void;
|
|
44
|
+
info(message: string, attrs?: LogAttrs, error?: unknown): void;
|
|
45
|
+
warn(message: string, attrs?: LogAttrs, error?: unknown): void;
|
|
7
46
|
}
|
|
8
47
|
declare function createLogger(module: string): PhotonLogger;
|
|
9
48
|
|
|
@@ -41,6 +80,23 @@ interface SetupOtelOptions {
|
|
|
41
80
|
* conflicts.
|
|
42
81
|
*/
|
|
43
82
|
headers?: Record<string, string>;
|
|
83
|
+
/**
|
|
84
|
+
* Auto-instrument outbound `globalThis.fetch` with CLIENT spans and W3C
|
|
85
|
+
* trace-context propagation. On Bun this is the only fetch instrumentation
|
|
86
|
+
* that works (diagnostics_channel-based instrumentations emit nothing on
|
|
87
|
+
* Bun's native fetch); it works identically on Node.
|
|
88
|
+
*
|
|
89
|
+
* `true` enables with defaults; pass an object to filter URLs via `ignore`.
|
|
90
|
+
* Defaults to enabled when a traces endpoint is configured. Pass `false` to
|
|
91
|
+
* disable.
|
|
92
|
+
*/
|
|
93
|
+
instrumentFetch?: boolean | InstrumentFetchOptions;
|
|
94
|
+
/**
|
|
95
|
+
* Minimum log level emitted by `createLogger()` (to both OTLP and console).
|
|
96
|
+
* The `LOG_LEVEL` env var still takes precedence. Defaults to `debug` in
|
|
97
|
+
* development and `info` otherwise.
|
|
98
|
+
*/
|
|
99
|
+
logLevel?: LogLevel;
|
|
44
100
|
/**
|
|
45
101
|
* Extra resource attributes attached to every span/log alongside
|
|
46
102
|
* `service.name` / `service.version`.
|
|
@@ -74,4 +130,4 @@ declare const PHOTON_OTEL_VERSION = "0.1.0";
|
|
|
74
130
|
declare function withSpan<T>(name: string, fn: () => Promise<T> | T): Promise<T>;
|
|
75
131
|
declare function withSpan<T>(name: string, attrs: LogAttrs, fn: () => Promise<T> | T): Promise<T>;
|
|
76
132
|
|
|
77
|
-
export { type LogAttrs, type OtelHandle, PHOTON_OTEL_VERSION, type PhotonLogger, type SetupOtelOptions, createLogger, isOtelActive, sanitizeEmail, sanitizeErrorMessage, sanitizePhone, setupOtel, withSpan };
|
|
133
|
+
export { type FetchInstrumentation, type InstrumentFetchOptions, type LogAttrs, type LogLevel, type OtelHandle, PHOTON_OTEL_VERSION, type PhotonLogger, type SetupOtelOptions, createLogger, getLogLevel, instrumentFetch, isOtelActive, sanitizeEmail, sanitizeErrorMessage, sanitizePhone, setLogLevel, setupOtel, withSpan };
|
package/dist/index.js
CHANGED
|
@@ -1,11 +1,250 @@
|
|
|
1
|
-
// src/
|
|
2
|
-
import {
|
|
3
|
-
|
|
1
|
+
// src/instrument-fetch.ts
|
|
2
|
+
import {
|
|
3
|
+
context,
|
|
4
|
+
propagation,
|
|
5
|
+
SpanKind,
|
|
6
|
+
SpanStatusCode,
|
|
7
|
+
trace
|
|
8
|
+
} from "@opentelemetry/api";
|
|
9
|
+
import {
|
|
10
|
+
ATTR_ERROR_TYPE,
|
|
11
|
+
ATTR_HTTP_REQUEST_METHOD,
|
|
12
|
+
ATTR_HTTP_RESPONSE_STATUS_CODE,
|
|
13
|
+
ATTR_SERVER_ADDRESS,
|
|
14
|
+
ATTR_SERVER_PORT,
|
|
15
|
+
ATTR_URL_FULL
|
|
16
|
+
} from "@opentelemetry/semantic-conventions";
|
|
17
|
+
|
|
18
|
+
// src/sanitize.ts
|
|
19
|
+
var PHONE_PATTERN = /\+?\d[\d\s()\-.]{6,18}\d/g;
|
|
20
|
+
var EMAIL_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
21
|
+
function sanitizePhone(input) {
|
|
22
|
+
const hasPlus = input.startsWith("+");
|
|
23
|
+
const digits = input.replace(/\D/g, "");
|
|
24
|
+
if (digits.length < 8) {
|
|
25
|
+
return hasPlus ? "+xxxx" : "xxxx";
|
|
26
|
+
}
|
|
27
|
+
const head = digits.slice(0, 3);
|
|
28
|
+
const tail = digits.slice(-4);
|
|
29
|
+
const middleLength = digits.length - head.length - tail.length;
|
|
30
|
+
return `${hasPlus ? "+" : ""}${head}${"x".repeat(middleLength)}${tail}`;
|
|
31
|
+
}
|
|
32
|
+
function sanitizeEmail(input) {
|
|
33
|
+
const atIndex = input.lastIndexOf("@");
|
|
34
|
+
if (atIndex < 1) {
|
|
35
|
+
return "***";
|
|
36
|
+
}
|
|
37
|
+
const local = input.slice(0, atIndex);
|
|
38
|
+
const domain = input.slice(atIndex + 1);
|
|
39
|
+
const dotIndex = domain.lastIndexOf(".");
|
|
40
|
+
if (dotIndex < 1) {
|
|
41
|
+
return "***";
|
|
42
|
+
}
|
|
43
|
+
const localHead = local.slice(0, 2);
|
|
44
|
+
const domainHead = domain.slice(0, 1);
|
|
45
|
+
const tld = domain.slice(dotIndex);
|
|
46
|
+
return `${localHead}***@${domainHead}***${tld}`;
|
|
47
|
+
}
|
|
48
|
+
function sanitizeErrorMessage(input) {
|
|
49
|
+
return input.replace(EMAIL_PATTERN, (match) => sanitizeEmail(match)).replace(PHONE_PATTERN, (match) => sanitizePhone(match));
|
|
50
|
+
}
|
|
4
51
|
|
|
5
52
|
// src/version.ts
|
|
6
53
|
var PHOTON_OTEL_VERSION = "0.1.0";
|
|
7
54
|
|
|
55
|
+
// src/instrument-fetch.ts
|
|
56
|
+
var PATCH_MARKER = /* @__PURE__ */ Symbol.for("@photon-ai/otel.fetch.original");
|
|
57
|
+
var HTTP_ERROR_STATUS_MIN = 400;
|
|
58
|
+
var DEFAULT_PORTS = { "https:": 443, "http:": 80 };
|
|
59
|
+
var scopedTracer;
|
|
60
|
+
function getTracer() {
|
|
61
|
+
if (!scopedTracer) {
|
|
62
|
+
scopedTracer = trace.getTracer("@photon-ai/otel", PHOTON_OTEL_VERSION);
|
|
63
|
+
}
|
|
64
|
+
return scopedTracer;
|
|
65
|
+
}
|
|
66
|
+
function setGlobalFetch(fn) {
|
|
67
|
+
globalThis.fetch = fn;
|
|
68
|
+
}
|
|
69
|
+
function getPatchOriginal(fn) {
|
|
70
|
+
return fn[PATCH_MARKER];
|
|
71
|
+
}
|
|
72
|
+
function setPatchOriginal(fn, original) {
|
|
73
|
+
fn[PATCH_MARKER] = original;
|
|
74
|
+
}
|
|
75
|
+
function preserveProps(from, to) {
|
|
76
|
+
for (const key of Object.getOwnPropertyNames(from)) {
|
|
77
|
+
if (key in to) {
|
|
78
|
+
continue;
|
|
79
|
+
}
|
|
80
|
+
const descriptor = Object.getOwnPropertyDescriptor(from, key);
|
|
81
|
+
if (descriptor) {
|
|
82
|
+
Object.defineProperty(to, key, descriptor);
|
|
83
|
+
}
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
function resolveRequestMeta(input, init) {
|
|
87
|
+
if (input instanceof Request) {
|
|
88
|
+
return { method: input.method, url: input.url };
|
|
89
|
+
}
|
|
90
|
+
const url = typeof input === "string" ? input : input.toString();
|
|
91
|
+
return { method: init?.method ?? "GET", url };
|
|
92
|
+
}
|
|
93
|
+
function resolvePort(parsed) {
|
|
94
|
+
if (parsed.port) {
|
|
95
|
+
return Number(parsed.port);
|
|
96
|
+
}
|
|
97
|
+
return DEFAULT_PORTS[parsed.protocol];
|
|
98
|
+
}
|
|
99
|
+
function toAttributes(attrs) {
|
|
100
|
+
const out = {};
|
|
101
|
+
for (const [key, value] of Object.entries(attrs)) {
|
|
102
|
+
if (value !== void 0) {
|
|
103
|
+
out[key] = value;
|
|
104
|
+
}
|
|
105
|
+
}
|
|
106
|
+
return out;
|
|
107
|
+
}
|
|
108
|
+
function fetchAttributes(method, url) {
|
|
109
|
+
const attrs = {
|
|
110
|
+
[ATTR_HTTP_REQUEST_METHOD]: method,
|
|
111
|
+
[ATTR_URL_FULL]: url
|
|
112
|
+
};
|
|
113
|
+
try {
|
|
114
|
+
const parsed = new URL(url);
|
|
115
|
+
attrs[ATTR_SERVER_ADDRESS] = parsed.hostname || void 0;
|
|
116
|
+
attrs[ATTR_SERVER_PORT] = resolvePort(parsed);
|
|
117
|
+
} catch {
|
|
118
|
+
}
|
|
119
|
+
return toAttributes(attrs);
|
|
120
|
+
}
|
|
121
|
+
function buildPropagatedHeaders(input, init) {
|
|
122
|
+
const headers = new Headers(
|
|
123
|
+
input instanceof Request ? input.headers : void 0
|
|
124
|
+
);
|
|
125
|
+
if (init?.headers) {
|
|
126
|
+
for (const [key, value] of new Headers(init.headers).entries()) {
|
|
127
|
+
headers.set(key, value);
|
|
128
|
+
}
|
|
129
|
+
}
|
|
130
|
+
propagation.inject(context.active(), headers, {
|
|
131
|
+
set: (carrier, key, value) => {
|
|
132
|
+
carrier.set(key, value);
|
|
133
|
+
}
|
|
134
|
+
});
|
|
135
|
+
return headers;
|
|
136
|
+
}
|
|
137
|
+
function callOriginal(original, input, init, headers) {
|
|
138
|
+
if (input instanceof Request) {
|
|
139
|
+
if (input.bodyUsed) {
|
|
140
|
+
for (const [key, value] of headers.entries()) {
|
|
141
|
+
input.headers.set(key, value);
|
|
142
|
+
}
|
|
143
|
+
return original(input, init);
|
|
144
|
+
}
|
|
145
|
+
return original(new Request(input, { ...init, headers }));
|
|
146
|
+
}
|
|
147
|
+
return original(input, { ...init, headers });
|
|
148
|
+
}
|
|
149
|
+
function buildWrappedFetch(original, options) {
|
|
150
|
+
return (input, init) => {
|
|
151
|
+
const { method, url } = resolveRequestMeta(input, init);
|
|
152
|
+
if (options?.ignore?.(url)) {
|
|
153
|
+
return original(input, init);
|
|
154
|
+
}
|
|
155
|
+
const name = method.toUpperCase();
|
|
156
|
+
return getTracer().startActiveSpan(
|
|
157
|
+
name,
|
|
158
|
+
{ kind: SpanKind.CLIENT },
|
|
159
|
+
async (span) => {
|
|
160
|
+
span.setAttributes(fetchAttributes(name, url));
|
|
161
|
+
try {
|
|
162
|
+
const headers = buildPropagatedHeaders(input, init);
|
|
163
|
+
const response = await callOriginal(original, input, init, headers);
|
|
164
|
+
span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, response.status);
|
|
165
|
+
span.setStatus({
|
|
166
|
+
code: response.status >= HTTP_ERROR_STATUS_MIN ? SpanStatusCode.ERROR : SpanStatusCode.OK
|
|
167
|
+
});
|
|
168
|
+
return response;
|
|
169
|
+
} catch (err) {
|
|
170
|
+
span.recordException(err);
|
|
171
|
+
const errorObj = err instanceof Error ? err : void 0;
|
|
172
|
+
span.setAttribute(
|
|
173
|
+
ATTR_ERROR_TYPE,
|
|
174
|
+
errorObj?.constructor.name ?? typeof err
|
|
175
|
+
);
|
|
176
|
+
span.setStatus({
|
|
177
|
+
code: SpanStatusCode.ERROR,
|
|
178
|
+
message: errorObj ? sanitizeErrorMessage(errorObj.message) : sanitizeErrorMessage(String(err))
|
|
179
|
+
});
|
|
180
|
+
throw err;
|
|
181
|
+
} finally {
|
|
182
|
+
span.end();
|
|
183
|
+
}
|
|
184
|
+
}
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
}
|
|
188
|
+
function instrumentFetch(options) {
|
|
189
|
+
const current = globalThis.fetch;
|
|
190
|
+
const existingOriginal = getPatchOriginal(current);
|
|
191
|
+
if (existingOriginal) {
|
|
192
|
+
return {
|
|
193
|
+
unpatch() {
|
|
194
|
+
if (globalThis.fetch === current) {
|
|
195
|
+
setGlobalFetch(existingOriginal);
|
|
196
|
+
}
|
|
197
|
+
}
|
|
198
|
+
};
|
|
199
|
+
}
|
|
200
|
+
const original = current;
|
|
201
|
+
const wrapped = buildWrappedFetch(original, options);
|
|
202
|
+
preserveProps(original, wrapped);
|
|
203
|
+
setPatchOriginal(wrapped, original);
|
|
204
|
+
setGlobalFetch(wrapped);
|
|
205
|
+
return {
|
|
206
|
+
unpatch() {
|
|
207
|
+
if (globalThis.fetch === wrapped) {
|
|
208
|
+
setGlobalFetch(original);
|
|
209
|
+
}
|
|
210
|
+
}
|
|
211
|
+
};
|
|
212
|
+
}
|
|
213
|
+
|
|
8
214
|
// src/logger.ts
|
|
215
|
+
import { context as otelContext } from "@opentelemetry/api";
|
|
216
|
+
import { logs, SeverityNumber } from "@opentelemetry/api-logs";
|
|
217
|
+
var LEVEL_SEVERITY = {
|
|
218
|
+
debug: SeverityNumber.DEBUG,
|
|
219
|
+
// 5
|
|
220
|
+
info: SeverityNumber.INFO,
|
|
221
|
+
// 9
|
|
222
|
+
warn: SeverityNumber.WARN,
|
|
223
|
+
// 13
|
|
224
|
+
error: SeverityNumber.ERROR,
|
|
225
|
+
// 17
|
|
226
|
+
silent: Number.POSITIVE_INFINITY
|
|
227
|
+
};
|
|
228
|
+
var levelOverride;
|
|
229
|
+
function envLevel() {
|
|
230
|
+
const raw = process.env.LOG_LEVEL?.toLowerCase();
|
|
231
|
+
if (raw && raw in LEVEL_SEVERITY) {
|
|
232
|
+
return raw;
|
|
233
|
+
}
|
|
234
|
+
return;
|
|
235
|
+
}
|
|
236
|
+
function defaultLevel() {
|
|
237
|
+
return (process.env.DEPLOYMENT_ENV ?? "development") === "development" ? "debug" : "info";
|
|
238
|
+
}
|
|
239
|
+
function resolveLevel() {
|
|
240
|
+
return envLevel() ?? levelOverride ?? defaultLevel();
|
|
241
|
+
}
|
|
242
|
+
function setLogLevel(level) {
|
|
243
|
+
levelOverride = level;
|
|
244
|
+
}
|
|
245
|
+
function getLogLevel() {
|
|
246
|
+
return resolveLevel();
|
|
247
|
+
}
|
|
9
248
|
var scopedLogger;
|
|
10
249
|
function getLogger() {
|
|
11
250
|
if (!scopedLogger) {
|
|
@@ -25,10 +264,26 @@ function filterUndefined(attrs) {
|
|
|
25
264
|
}
|
|
26
265
|
return out;
|
|
27
266
|
}
|
|
267
|
+
function consoleFor(severityNumber) {
|
|
268
|
+
if (severityNumber >= SeverityNumber.ERROR) {
|
|
269
|
+
return console.error;
|
|
270
|
+
}
|
|
271
|
+
if (severityNumber >= SeverityNumber.WARN) {
|
|
272
|
+
return console.warn;
|
|
273
|
+
}
|
|
274
|
+
if (severityNumber >= SeverityNumber.INFO) {
|
|
275
|
+
return console.info;
|
|
276
|
+
}
|
|
277
|
+
return console.debug;
|
|
278
|
+
}
|
|
28
279
|
function emit(severityNumber, severityText, module, message, attrs, error) {
|
|
280
|
+
if (severityNumber < LEVEL_SEVERITY[resolveLevel()]) {
|
|
281
|
+
return;
|
|
282
|
+
}
|
|
283
|
+
const userAttrs = filterUndefined(attrs);
|
|
29
284
|
const attributes = {
|
|
30
285
|
"log.module": module,
|
|
31
|
-
...
|
|
286
|
+
...userAttrs
|
|
32
287
|
};
|
|
33
288
|
if (error instanceof Error) {
|
|
34
289
|
attributes["exception.type"] = error.name;
|
|
@@ -36,6 +291,9 @@ function emit(severityNumber, severityText, module, message, attrs, error) {
|
|
|
36
291
|
if (error.stack) {
|
|
37
292
|
attributes["exception.stacktrace"] = error.stack;
|
|
38
293
|
}
|
|
294
|
+
} else if (error !== void 0) {
|
|
295
|
+
attributes["exception.type"] = typeof error;
|
|
296
|
+
attributes["exception.message"] = String(error);
|
|
39
297
|
}
|
|
40
298
|
getLogger().emit({
|
|
41
299
|
severityNumber,
|
|
@@ -44,60 +302,33 @@ function emit(severityNumber, severityText, module, message, attrs, error) {
|
|
|
44
302
|
attributes,
|
|
45
303
|
context: otelContext.active()
|
|
46
304
|
});
|
|
47
|
-
const
|
|
48
|
-
if (
|
|
49
|
-
|
|
50
|
-
} else {
|
|
51
|
-
console.log(prefix, message);
|
|
305
|
+
const extras = [];
|
|
306
|
+
if (Object.keys(userAttrs).length > 0) {
|
|
307
|
+
extras.push(userAttrs);
|
|
52
308
|
}
|
|
309
|
+
if (error !== void 0) {
|
|
310
|
+
extras.push(error);
|
|
311
|
+
}
|
|
312
|
+
consoleFor(severityNumber)(`[${module}]`, severityText, message, ...extras);
|
|
53
313
|
}
|
|
54
314
|
function createLogger(module) {
|
|
55
315
|
return {
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
316
|
+
debug: (message, attrs, error) => emit(SeverityNumber.DEBUG, "DEBUG", module, message, attrs, error),
|
|
317
|
+
info: (message, attrs, error) => emit(SeverityNumber.INFO, "INFO", module, message, attrs, error),
|
|
318
|
+
warn: (message, attrs, error) => emit(SeverityNumber.WARN, "WARN", module, message, attrs, error),
|
|
319
|
+
error: (message, attrs, error) => emit(SeverityNumber.ERROR, "ERROR", module, message, attrs, error)
|
|
60
320
|
};
|
|
61
321
|
}
|
|
62
322
|
|
|
63
|
-
// src/sanitize.ts
|
|
64
|
-
var PHONE_PATTERN = /\+?\d[\d\s()\-.]{6,18}\d/g;
|
|
65
|
-
var EMAIL_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,}/g;
|
|
66
|
-
function sanitizePhone(input) {
|
|
67
|
-
const hasPlus = input.startsWith("+");
|
|
68
|
-
const digits = input.replace(/\D/g, "");
|
|
69
|
-
if (digits.length < 8) {
|
|
70
|
-
return hasPlus ? "+xxxx" : "xxxx";
|
|
71
|
-
}
|
|
72
|
-
const head = digits.slice(0, 3);
|
|
73
|
-
const tail = digits.slice(-4);
|
|
74
|
-
const middleLength = digits.length - head.length - tail.length;
|
|
75
|
-
return `${hasPlus ? "+" : ""}${head}${"x".repeat(middleLength)}${tail}`;
|
|
76
|
-
}
|
|
77
|
-
function sanitizeEmail(input) {
|
|
78
|
-
const atIndex = input.lastIndexOf("@");
|
|
79
|
-
if (atIndex < 1) {
|
|
80
|
-
return "***";
|
|
81
|
-
}
|
|
82
|
-
const local = input.slice(0, atIndex);
|
|
83
|
-
const domain = input.slice(atIndex + 1);
|
|
84
|
-
const dotIndex = domain.lastIndexOf(".");
|
|
85
|
-
if (dotIndex < 1) {
|
|
86
|
-
return "***";
|
|
87
|
-
}
|
|
88
|
-
const localHead = local.slice(0, 2);
|
|
89
|
-
const domainHead = domain.slice(0, 1);
|
|
90
|
-
const tld = domain.slice(dotIndex);
|
|
91
|
-
return `${localHead}***@${domainHead}***${tld}`;
|
|
92
|
-
}
|
|
93
|
-
function sanitizeErrorMessage(input) {
|
|
94
|
-
return input.replace(EMAIL_PATTERN, (match) => sanitizeEmail(match)).replace(PHONE_PATTERN, (match) => sanitizePhone(match));
|
|
95
|
-
}
|
|
96
|
-
|
|
97
323
|
// src/setup.ts
|
|
98
|
-
import { context, trace } from "@opentelemetry/api";
|
|
324
|
+
import { context as context2, propagation as propagation2, trace as trace2 } from "@opentelemetry/api";
|
|
99
325
|
import { logs as logs2 } from "@opentelemetry/api-logs";
|
|
100
326
|
import { AsyncLocalStorageContextManager } from "@opentelemetry/context-async-hooks";
|
|
327
|
+
import {
|
|
328
|
+
CompositePropagator,
|
|
329
|
+
W3CBaggagePropagator,
|
|
330
|
+
W3CTraceContextPropagator
|
|
331
|
+
} from "@opentelemetry/core";
|
|
101
332
|
import { OTLPLogExporter } from "@opentelemetry/exporter-logs-otlp-http";
|
|
102
333
|
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
|
|
103
334
|
import { resourceFromAttributes } from "@opentelemetry/resources";
|
|
@@ -145,10 +376,49 @@ function resolveLogsEndpoint(base) {
|
|
|
145
376
|
const generic = process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? base;
|
|
146
377
|
return generic ? `${generic.replace(TRAILING_SLASH, "")}/v1/logs` : void 0;
|
|
147
378
|
}
|
|
379
|
+
function otlpEndpointKey(url) {
|
|
380
|
+
try {
|
|
381
|
+
const parsed = new URL(url);
|
|
382
|
+
return `${parsed.origin}${parsed.pathname.replace(TRAILING_SLASH, "")}`;
|
|
383
|
+
} catch {
|
|
384
|
+
return;
|
|
385
|
+
}
|
|
386
|
+
}
|
|
387
|
+
function otlpEndpointKeysOf(tracesEndpoint, logsEndpoint) {
|
|
388
|
+
const keys = [];
|
|
389
|
+
for (const endpoint of [tracesEndpoint, logsEndpoint]) {
|
|
390
|
+
if (!endpoint) {
|
|
391
|
+
continue;
|
|
392
|
+
}
|
|
393
|
+
const key = otlpEndpointKey(endpoint);
|
|
394
|
+
if (key) {
|
|
395
|
+
keys.push(key);
|
|
396
|
+
}
|
|
397
|
+
}
|
|
398
|
+
return keys;
|
|
399
|
+
}
|
|
400
|
+
function startFetchInstrumentation(option, hasTraces, tracesEndpoint, logsEndpoint) {
|
|
401
|
+
const want = option ?? hasTraces;
|
|
402
|
+
if (!want) {
|
|
403
|
+
return;
|
|
404
|
+
}
|
|
405
|
+
const userOptions = typeof option === "object" ? option : void 0;
|
|
406
|
+
const otlpEndpointKeys = otlpEndpointKeysOf(tracesEndpoint, logsEndpoint);
|
|
407
|
+
return instrumentFetch({
|
|
408
|
+
ignore: (url) => {
|
|
409
|
+
const key = otlpEndpointKey(url);
|
|
410
|
+
const isOtlpEndpoint = key !== void 0 && otlpEndpointKeys.includes(key);
|
|
411
|
+
return isOtlpEndpoint || (userOptions?.ignore?.(url) ?? false);
|
|
412
|
+
}
|
|
413
|
+
});
|
|
414
|
+
}
|
|
148
415
|
function setupOtel(options) {
|
|
149
416
|
if (activeHandle) {
|
|
150
417
|
return activeHandle;
|
|
151
418
|
}
|
|
419
|
+
if (options.logLevel) {
|
|
420
|
+
setLogLevel(options.logLevel);
|
|
421
|
+
}
|
|
152
422
|
const tracesEndpoint = resolveTracesEndpoint(options.endpoint);
|
|
153
423
|
const logsEndpoint = resolveLogsEndpoint(options.endpoint);
|
|
154
424
|
const mergedHeaders = {
|
|
@@ -162,7 +432,15 @@ function setupOtel(options) {
|
|
|
162
432
|
"deployment.environment": process.env.DEPLOYMENT_ENV ?? "development",
|
|
163
433
|
...options.resourceAttributes
|
|
164
434
|
});
|
|
165
|
-
|
|
435
|
+
context2.setGlobalContextManager(new AsyncLocalStorageContextManager());
|
|
436
|
+
propagation2.setGlobalPropagator(
|
|
437
|
+
new CompositePropagator({
|
|
438
|
+
propagators: [
|
|
439
|
+
new W3CTraceContextPropagator(),
|
|
440
|
+
new W3CBaggagePropagator()
|
|
441
|
+
]
|
|
442
|
+
})
|
|
443
|
+
);
|
|
166
444
|
const traceProcessors = tracesEndpoint ? [
|
|
167
445
|
new BatchSpanProcessor(
|
|
168
446
|
new OTLPTraceExporter({
|
|
@@ -175,7 +453,13 @@ function setupOtel(options) {
|
|
|
175
453
|
resource,
|
|
176
454
|
spanProcessors: traceProcessors
|
|
177
455
|
});
|
|
178
|
-
|
|
456
|
+
trace2.setGlobalTracerProvider(tracerProvider);
|
|
457
|
+
const fetchInstrumentation = startFetchInstrumentation(
|
|
458
|
+
options.instrumentFetch,
|
|
459
|
+
traceProcessors.length > 0,
|
|
460
|
+
tracesEndpoint,
|
|
461
|
+
logsEndpoint
|
|
462
|
+
);
|
|
179
463
|
const logProcessors = logsEndpoint ? [
|
|
180
464
|
new BatchLogRecordProcessor(
|
|
181
465
|
new OTLPLogExporter({
|
|
@@ -191,6 +475,7 @@ function setupOtel(options) {
|
|
|
191
475
|
logs2.setGlobalLoggerProvider(loggerProvider);
|
|
192
476
|
const handle = {
|
|
193
477
|
async shutdown() {
|
|
478
|
+
fetchInstrumentation?.unpatch();
|
|
194
479
|
await Promise.allSettled([
|
|
195
480
|
tracerProvider.shutdown(),
|
|
196
481
|
loggerProvider.shutdown()
|
|
@@ -207,17 +492,17 @@ function isOtelActive() {
|
|
|
207
492
|
|
|
208
493
|
// src/with-span.ts
|
|
209
494
|
import {
|
|
210
|
-
SpanStatusCode,
|
|
211
|
-
trace as
|
|
495
|
+
SpanStatusCode as SpanStatusCode2,
|
|
496
|
+
trace as trace3
|
|
212
497
|
} from "@opentelemetry/api";
|
|
213
|
-
var
|
|
214
|
-
function
|
|
215
|
-
if (!
|
|
216
|
-
|
|
498
|
+
var scopedTracer2;
|
|
499
|
+
function getTracer2() {
|
|
500
|
+
if (!scopedTracer2) {
|
|
501
|
+
scopedTracer2 = trace3.getTracer("@photon-ai/otel", PHOTON_OTEL_VERSION);
|
|
217
502
|
}
|
|
218
|
-
return
|
|
503
|
+
return scopedTracer2;
|
|
219
504
|
}
|
|
220
|
-
function
|
|
505
|
+
function toAttributes2(attrs) {
|
|
221
506
|
const out = {};
|
|
222
507
|
for (const [k, v] of Object.entries(attrs)) {
|
|
223
508
|
if (v !== void 0) {
|
|
@@ -232,20 +517,20 @@ function withSpan(name, attrsOrFn, maybeFn) {
|
|
|
232
517
|
throw new Error("withSpan: function argument is required");
|
|
233
518
|
}
|
|
234
519
|
const attrs = typeof attrsOrFn === "function" ? void 0 : attrsOrFn;
|
|
235
|
-
return
|
|
520
|
+
return getTracer2().startActiveSpan(name, async (span) => {
|
|
236
521
|
if (attrs) {
|
|
237
|
-
span.setAttributes(
|
|
522
|
+
span.setAttributes(toAttributes2(attrs));
|
|
238
523
|
}
|
|
239
524
|
try {
|
|
240
525
|
const result = await fn();
|
|
241
|
-
span.setStatus({ code:
|
|
526
|
+
span.setStatus({ code: SpanStatusCode2.OK });
|
|
242
527
|
return result;
|
|
243
528
|
} catch (err) {
|
|
244
529
|
span.recordException(err);
|
|
245
530
|
const errorObj = err instanceof Error ? err : void 0;
|
|
246
531
|
span.setAttribute("error.type", errorObj?.constructor.name ?? typeof err);
|
|
247
532
|
span.setStatus({
|
|
248
|
-
code:
|
|
533
|
+
code: SpanStatusCode2.ERROR,
|
|
249
534
|
message: errorObj ? sanitizeErrorMessage(errorObj.message) : sanitizeErrorMessage(String(err))
|
|
250
535
|
});
|
|
251
536
|
throw err;
|
|
@@ -257,10 +542,13 @@ function withSpan(name, attrsOrFn, maybeFn) {
|
|
|
257
542
|
export {
|
|
258
543
|
PHOTON_OTEL_VERSION,
|
|
259
544
|
createLogger,
|
|
545
|
+
getLogLevel,
|
|
546
|
+
instrumentFetch,
|
|
260
547
|
isOtelActive,
|
|
261
548
|
sanitizeEmail,
|
|
262
549
|
sanitizeErrorMessage,
|
|
263
550
|
sanitizePhone,
|
|
551
|
+
setLogLevel,
|
|
264
552
|
setupOtel,
|
|
265
553
|
withSpan
|
|
266
554
|
};
|
package/dist/index.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"sources":["../src/logger.ts","../src/version.ts","../src/sanitize.ts","../src/setup.ts","../src/with-span.ts"],"sourcesContent":["import { context as otelContext } from \"@opentelemetry/api\";\nimport { type Logger, logs, SeverityNumber } from \"@opentelemetry/api-logs\";\nimport { PHOTON_OTEL_VERSION } from \"./version\";\n\nexport type LogAttrs = Record<string, string | number | boolean | undefined>;\n\nlet scopedLogger: Logger | undefined;\n\nfunction getLogger(): Logger {\n if (!scopedLogger) {\n scopedLogger = logs.getLogger(\"@photon-ai/otel\", PHOTON_OTEL_VERSION);\n }\n return scopedLogger;\n}\n\nfunction filterUndefined(\n attrs?: LogAttrs\n): Record<string, string | number | boolean> {\n if (!attrs) {\n return {};\n }\n const out: Record<string, string | number | boolean> = {};\n for (const [k, v] of Object.entries(attrs)) {\n if (v !== undefined) {\n out[k] = v;\n }\n }\n return out;\n}\n\nfunction emit(\n severityNumber: SeverityNumber,\n severityText: string,\n module: string,\n message: string,\n attrs?: LogAttrs,\n error?: unknown\n): void {\n const attributes: Record<string, string | number | boolean> = {\n \"log.module\": module,\n ...filterUndefined(attrs),\n };\n\n if (error instanceof Error) {\n attributes[\"exception.type\"] = error.name;\n attributes[\"exception.message\"] = error.message;\n if (error.stack) {\n attributes[\"exception.stacktrace\"] = error.stack;\n }\n }\n\n getLogger().emit({\n severityNumber,\n severityText,\n body: message,\n attributes,\n context: otelContext.active(),\n });\n\n const prefix = `[${module}]`;\n if (severityNumber >= SeverityNumber.ERROR) {\n console.error(prefix, message, ...(error ? [error] : []));\n } else {\n console.log(prefix, message);\n }\n}\n\nexport interface PhotonLogger {\n debug(message: string, attrs?: LogAttrs): void;\n error(message: string, attrs?: LogAttrs, error?: unknown): void;\n info(message: string, attrs?: LogAttrs): void;\n warn(message: string, attrs?: LogAttrs): void;\n}\n\nexport function createLogger(module: string): PhotonLogger {\n return {\n info: (message, attrs) =>\n emit(SeverityNumber.INFO, \"INFO\", module, message, attrs),\n warn: (message, attrs) =>\n emit(SeverityNumber.WARN, \"WARN\", module, message, attrs),\n error: (message, attrs, error) =>\n emit(SeverityNumber.ERROR, \"ERROR\", module, message, attrs, error),\n debug: (message, attrs) =>\n emit(SeverityNumber.DEBUG, \"DEBUG\", module, message, attrs),\n };\n}\n","export const PHOTON_OTEL_VERSION = \"0.1.0\";\n","// E.164-ish phone match: optional `+`, 7–15 digits with optional separators.\nconst PHONE_PATTERN = /\\+?\\d[\\d\\s()\\-.]{6,18}\\d/g;\nconst EMAIL_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}/g;\n\n/**\n * Mask a phone number, keeping the leading `+` (if any) plus the first 3 digits\n * and the last 4 digits visible. Example: `+13315553374` -> `+133xxxxx3374`.\n *\n * Inputs that don't have enough digits to safely mask are returned as\n * `xxxx` to avoid leaking the entire short value.\n */\nexport function sanitizePhone(input: string): string {\n const hasPlus = input.startsWith(\"+\");\n const digits = input.replace(/\\D/g, \"\");\n if (digits.length < 8) {\n return hasPlus ? \"+xxxx\" : \"xxxx\";\n }\n const head = digits.slice(0, 3);\n const tail = digits.slice(-4);\n const middleLength = digits.length - head.length - tail.length;\n return `${hasPlus ? \"+\" : \"\"}${head}${\"x\".repeat(middleLength)}${tail}`;\n}\n\n/**\n * Mask an email address, keeping the first 2 chars of the local part, the\n * first char of the domain, and the TLD. Example:\n * `foo.bar@example.com` -> `fo***@e***.com`.\n */\nexport function sanitizeEmail(input: string): string {\n const atIndex = input.lastIndexOf(\"@\");\n if (atIndex < 1) {\n return \"***\";\n }\n const local = input.slice(0, atIndex);\n const domain = input.slice(atIndex + 1);\n const dotIndex = domain.lastIndexOf(\".\");\n if (dotIndex < 1) {\n return \"***\";\n }\n const localHead = local.slice(0, 2);\n const domainHead = domain.slice(0, 1);\n const tld = domain.slice(dotIndex);\n return `${localHead}***@${domainHead}***${tld}`;\n}\n\n/**\n * Replace every phone number and email address inside a free-form string with\n * its sanitized form. Used to scrub `Error.message` values before attaching\n * them to span status.\n */\nexport function sanitizeErrorMessage(input: string): string {\n return input\n .replace(EMAIL_PATTERN, (match) => sanitizeEmail(match))\n .replace(PHONE_PATTERN, (match) => sanitizePhone(match));\n}\n","import { context, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport { AsyncLocalStorageContextManager } from \"@opentelemetry/context-async-hooks\";\nimport { OTLPLogExporter } from \"@opentelemetry/exporter-logs-otlp-http\";\nimport { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-http\";\nimport { resourceFromAttributes } from \"@opentelemetry/resources\";\nimport {\n BatchLogRecordProcessor,\n LoggerProvider,\n} from \"@opentelemetry/sdk-logs\";\nimport {\n BasicTracerProvider,\n BatchSpanProcessor,\n} from \"@opentelemetry/sdk-trace-base\";\n\nexport interface SetupOtelOptions {\n /**\n * Default OTLP/HTTP base endpoint (e.g. `https://otel.example.com`). The\n * `/v1/traces` and `/v1/logs` paths are appended automatically. Standard\n * `OTEL_EXPORTER_OTLP_*` env vars always take precedence.\n */\n endpoint?: string;\n /**\n * Default OTLP headers (e.g. `{ Authorization: \"Basic ...\" }`). Merged with\n * any headers parsed from `OTEL_EXPORTER_OTLP_HEADERS`; env values win on\n * conflicts.\n */\n headers?: Record<string, string>;\n /**\n * Extra resource attributes attached to every span/log alongside\n * `service.name` / `service.version`.\n */\n resourceAttributes?: Record<string, string | number | boolean>;\n serviceName: string;\n serviceVersion?: string;\n}\n\nexport interface OtelHandle {\n shutdown(): Promise<void>;\n}\n\nlet activeHandle: OtelHandle | undefined;\n\nconst TRAILING_SLASH = /\\/$/;\n\nfunction parseEnvHeaders(raw: string | undefined): Record<string, string> {\n if (!raw) {\n return {};\n }\n const out: Record<string, string> = {};\n for (const pair of raw.split(\",\")) {\n const eq = pair.indexOf(\"=\");\n if (eq <= 0) {\n continue;\n }\n const key = pair.slice(0, eq).trim();\n const value = pair.slice(eq + 1).trim();\n if (key) {\n out[key] = value;\n }\n }\n return out;\n}\n\nfunction resolveTracesEndpoint(base: string | undefined): string | undefined {\n const traces = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;\n if (traces) {\n return traces;\n }\n const generic = process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? base;\n return generic\n ? `${generic.replace(TRAILING_SLASH, \"\")}/v1/traces`\n : undefined;\n}\n\nfunction resolveLogsEndpoint(base: string | undefined): string | undefined {\n const logsEndpoint = process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT;\n if (logsEndpoint) {\n return logsEndpoint;\n }\n const generic = process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? base;\n return generic ? `${generic.replace(TRAILING_SLASH, \"\")}/v1/logs` : undefined;\n}\n\n/**\n * Boot an OTLP/HTTP-based OpenTelemetry pipeline (traces + logs).\n *\n * Idempotent: calling twice in the same process is a no-op on the second\n * call, so libraries can safely invoke this without clobbering an app-level\n * OTel setup that ran earlier.\n *\n * Standard `OTEL_EXPORTER_OTLP_*` env vars override the `endpoint` and\n * `headers` arguments — this matches the OpenTelemetry SDK config spec.\n */\nexport function setupOtel(options: SetupOtelOptions): OtelHandle {\n if (activeHandle) {\n return activeHandle;\n }\n\n const tracesEndpoint = resolveTracesEndpoint(options.endpoint);\n const logsEndpoint = resolveLogsEndpoint(options.endpoint);\n const mergedHeaders = {\n ...options.headers,\n ...parseEnvHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS),\n };\n const hasHeaders = Object.keys(mergedHeaders).length > 0;\n\n const resource = resourceFromAttributes({\n \"service.name\": options.serviceName,\n ...(options.serviceVersion\n ? { \"service.version\": options.serviceVersion }\n : {}),\n \"deployment.environment\": process.env.DEPLOYMENT_ENV ?? \"development\",\n ...options.resourceAttributes,\n });\n\n context.setGlobalContextManager(new AsyncLocalStorageContextManager());\n\n const traceProcessors = tracesEndpoint\n ? [\n new BatchSpanProcessor(\n new OTLPTraceExporter({\n url: tracesEndpoint,\n headers: hasHeaders ? mergedHeaders : undefined,\n })\n ),\n ]\n : [];\n\n const tracerProvider = new BasicTracerProvider({\n resource,\n spanProcessors: traceProcessors,\n });\n trace.setGlobalTracerProvider(tracerProvider);\n\n const logProcessors = logsEndpoint\n ? [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\n url: logsEndpoint,\n headers: hasHeaders ? mergedHeaders : undefined,\n })\n ),\n ]\n : [];\n\n const loggerProvider = new LoggerProvider({\n resource,\n processors: logProcessors,\n });\n logs.setGlobalLoggerProvider(loggerProvider);\n\n const handle: OtelHandle = {\n async shutdown() {\n await Promise.allSettled([\n tracerProvider.shutdown(),\n loggerProvider.shutdown(),\n ]);\n activeHandle = undefined;\n },\n };\n\n activeHandle = handle;\n return handle;\n}\n\n/**\n * Read-only accessor for tests / debug paths that need to know whether\n * `setupOtel` has already run in this process.\n */\nexport function isOtelActive(): boolean {\n return activeHandle !== undefined;\n}\n","import {\n type Attributes,\n SpanStatusCode,\n type Tracer,\n trace,\n} from \"@opentelemetry/api\";\nimport type { LogAttrs } from \"./logger\";\nimport { sanitizeErrorMessage } from \"./sanitize\";\nimport { PHOTON_OTEL_VERSION } from \"./version\";\n\nlet scopedTracer: Tracer | undefined;\n\nfunction getTracer(): Tracer {\n if (!scopedTracer) {\n scopedTracer = trace.getTracer(\"@photon-ai/otel\", PHOTON_OTEL_VERSION);\n }\n return scopedTracer;\n}\n\nfunction toAttributes(attrs: LogAttrs): Attributes {\n const out: Attributes = {};\n for (const [k, v] of Object.entries(attrs)) {\n if (v !== undefined) {\n out[k] = v;\n }\n }\n return out;\n}\n\nexport function withSpan<T>(name: string, fn: () => Promise<T> | T): Promise<T>;\nexport function withSpan<T>(\n name: string,\n attrs: LogAttrs,\n fn: () => Promise<T> | T\n): Promise<T>;\nexport function withSpan<T>(\n name: string,\n attrsOrFn: LogAttrs | (() => Promise<T> | T),\n maybeFn?: () => Promise<T> | T\n): Promise<T> {\n const fn = typeof attrsOrFn === \"function\" ? attrsOrFn : maybeFn;\n if (!fn) {\n throw new Error(\"withSpan: function argument is required\");\n }\n const attrs = typeof attrsOrFn === \"function\" ? undefined : attrsOrFn;\n\n return getTracer().startActiveSpan(name, async (span) => {\n if (attrs) {\n span.setAttributes(toAttributes(attrs));\n }\n try {\n const result = await fn();\n span.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (err) {\n span.recordException(err as Error);\n const errorObj = err instanceof Error ? err : undefined;\n span.setAttribute(\"error.type\", errorObj?.constructor.name ?? typeof err);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: errorObj\n ? sanitizeErrorMessage(errorObj.message)\n : sanitizeErrorMessage(String(err)),\n });\n throw err;\n } finally {\n span.end();\n }\n });\n}\n"],"mappings":";AAAA,SAAS,WAAW,mBAAmB;AACvC,SAAsB,MAAM,sBAAsB;;;ACD3C,IAAM,sBAAsB;;;ADMnC,IAAI;AAEJ,SAAS,YAAoB;AAC3B,MAAI,CAAC,cAAc;AACjB,mBAAe,KAAK,UAAU,mBAAmB,mBAAmB;AAAA,EACtE;AACA,SAAO;AACT;AAEA,SAAS,gBACP,OAC2C;AAC3C,MAAI,CAAC,OAAO;AACV,WAAO,CAAC;AAAA,EACV;AACA,QAAM,MAAiD,CAAC;AACxD,aAAW,CAAC,GAAG,CAAC,KA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AACnB,UAAI,CAAC,IAAI;AAAA,IACX;AAAA,EACF;AACA,SAAO;AACT;AAQO,SAAS,SACd,MACA,WACA,SACY;AACZ,QAAM,KAAK,OAAO,cAAc,aAAa,YAAY;AACzD,MAAI,CAAC,IAAI;AACP,UAAM,IAAI,MAAM,yCAAyC;AAAA,EAC3D;AACA,QAAM,QAAQ,OAAO,cAAc,aAAa,SAAY;AAE5D,SAAO,UAAU,EAAE,gBAAgB,MAAM,OAAO,SAAS;AACvD,QAAI,OAAO;AACT,WAAK,cAAc,aAAa,KAAK,CAAC;AAAA,IACxC;AACA,QAAI;AACF,YAAM,SAAS,MAAM,GAAG;AACxB,WAAK,UAAU,EAAE,MAAM,eAAe,GAAG,CAAC;AAC1C,aAAO;AAAA,IACT,SAAS,KAAK;AACZ,WAAK,gBAAgB,GAAY;AACjC,YAAM,WAAW,eAAe,QAAQ,MAAM;AAC9C,WAAK,aAAa,cAAc,UAAU,YAAY,QAAQ,OAAO,GAAG;AACxE,WAAK,UAAU;AAAA,QACb,MAAM,eAAe;AAAA,QACrB,SAAS,WACL,qBAAqB,SAAS,OAAO,IACrC,qBAAqB,OAAO,GAAG,CAAC;AAAA,MACtC,CAAC;AACD,YAAM;AAAA,IACR,UAAE;AACA,WAAK,IAAI;AAAA,IACX;AAAA,EACF,CAAC;AACH;","names":["logs","trace","trace"]}
|
|
1
|
+
{"version":3,"sources":["../src/instrument-fetch.ts","../src/sanitize.ts","../src/version.ts","../src/logger.ts","../src/setup.ts","../src/with-span.ts"],"sourcesContent":["import {\n type Attributes,\n context,\n propagation,\n SpanKind,\n SpanStatusCode,\n type Tracer,\n trace,\n} from \"@opentelemetry/api\";\nimport {\n ATTR_ERROR_TYPE,\n ATTR_HTTP_REQUEST_METHOD,\n ATTR_HTTP_RESPONSE_STATUS_CODE,\n ATTR_SERVER_ADDRESS,\n ATTR_SERVER_PORT,\n ATTR_URL_FULL,\n} from \"@opentelemetry/semantic-conventions\";\nimport { sanitizeErrorMessage } from \"./sanitize\";\nimport { PHOTON_OTEL_VERSION } from \"./version\";\n\nexport interface InstrumentFetchOptions {\n /**\n * Return `true` to skip instrumenting a request whose absolute URL is passed\n * in. Useful to drop noisy endpoints or URLs that carry secrets in their\n * query string. The request is still performed — only the span is skipped.\n */\n ignore?: (url: string) => boolean;\n}\n\nexport interface FetchInstrumentation {\n /** Restore the original `globalThis.fetch`. Safe to call more than once. */\n unpatch(): void;\n}\n\ntype FetchInput = Parameters<typeof fetch>[0];\ntype FetchInit = Parameters<typeof fetch>[1];\ntype FetchFn = (input: FetchInput, init?: FetchInit) => Promise<Response>;\n\n/**\n * Stored on the wrapper via the global symbol registry (`Symbol.for`) so the\n * double-wrap guard holds even when two copies of this module load — which can\n * happen because the `bun` export condition serves `src/` while `default`\n * serves `dist/`.\n */\nconst PATCH_MARKER = Symbol.for(\"@photon-ai/otel.fetch.original\");\n\nconst HTTP_ERROR_STATUS_MIN = 400;\nconst DEFAULT_PORTS: Record<string, number> = { \"https:\": 443, \"http:\": 80 };\n\nlet scopedTracer: Tracer | undefined;\n\nfunction getTracer(): Tracer {\n if (!scopedTracer) {\n scopedTracer = trace.getTracer(\"@photon-ai/otel\", PHOTON_OTEL_VERSION);\n }\n return scopedTracer;\n}\n\nfunction setGlobalFetch(fn: FetchFn): void {\n // `preconnect` (Bun) is copied onto wrappers by preserveProps; the cast just\n // tells TypeScript the runtime object satisfies the full `fetch` type.\n globalThis.fetch = fn as typeof fetch;\n}\n\nfunction getPatchOriginal(fn: FetchFn): FetchFn | undefined {\n return (fn as unknown as Record<symbol, FetchFn | undefined>)[PATCH_MARKER];\n}\n\nfunction setPatchOriginal(fn: FetchFn, original: FetchFn): void {\n (fn as unknown as Record<symbol, FetchFn>)[PATCH_MARKER] = original;\n}\n\n/** Copy extra own properties (e.g. Bun's `fetch.preconnect`) onto the wrapper. */\nfunction preserveProps(from: FetchFn, to: FetchFn): void {\n for (const key of Object.getOwnPropertyNames(from)) {\n if (key in to) {\n continue;\n }\n const descriptor = Object.getOwnPropertyDescriptor(from, key);\n if (descriptor) {\n Object.defineProperty(to, key, descriptor);\n }\n }\n}\n\nfunction resolveRequestMeta(\n input: FetchInput,\n init: FetchInit\n): { method: string; url: string } {\n if (input instanceof Request) {\n return { method: input.method, url: input.url };\n }\n const url = typeof input === \"string\" ? input : input.toString();\n return { method: init?.method ?? \"GET\", url };\n}\n\nfunction resolvePort(parsed: URL): number | undefined {\n if (parsed.port) {\n return Number(parsed.port);\n }\n return DEFAULT_PORTS[parsed.protocol];\n}\n\nfunction toAttributes(attrs: Attributes): Attributes {\n const out: Attributes = {};\n for (const [key, value] of Object.entries(attrs)) {\n if (value !== undefined) {\n out[key] = value;\n }\n }\n return out;\n}\n\nfunction fetchAttributes(method: string, url: string): Attributes {\n const attrs: Attributes = {\n [ATTR_HTTP_REQUEST_METHOD]: method,\n [ATTR_URL_FULL]: url,\n };\n try {\n const parsed = new URL(url);\n attrs[ATTR_SERVER_ADDRESS] = parsed.hostname || undefined;\n attrs[ATTR_SERVER_PORT] = resolvePort(parsed);\n } catch {\n // Unparseable URL: leave server.* unset rather than failing the request.\n }\n return toAttributes(attrs);\n}\n\n/** Build the outgoing headers and inject the active trace context into them. */\nfunction buildPropagatedHeaders(input: FetchInput, init: FetchInit): Headers {\n const headers = new Headers(\n input instanceof Request ? input.headers : undefined\n );\n if (init?.headers) {\n for (const [key, value] of new Headers(init.headers).entries()) {\n headers.set(key, value);\n }\n }\n propagation.inject(context.active(), headers, {\n set: (carrier, key, value) => {\n carrier.set(key, value);\n },\n });\n return headers;\n}\n\nfunction callOriginal(\n original: FetchFn,\n input: FetchInput,\n init: FetchInit,\n headers: Headers\n): Promise<Response> {\n if (input instanceof Request) {\n // A consumed Request's body can't be rebuilt, but its headers stay mutable\n // (verified on both Bun and Node) — inject the propagated context in place\n // so trace headers still flow without reconstructing the unusable Request.\n if (input.bodyUsed) {\n for (const [key, value] of headers.entries()) {\n input.headers.set(key, value);\n }\n return original(input, init);\n }\n return original(new Request(input, { ...init, headers }));\n }\n return original(input, { ...init, headers });\n}\n\nfunction buildWrappedFetch(\n original: FetchFn,\n options?: InstrumentFetchOptions\n): FetchFn {\n return (input, init) => {\n const { method, url } = resolveRequestMeta(input, init);\n if (options?.ignore?.(url)) {\n return original(input, init);\n }\n const name = method.toUpperCase();\n return getTracer().startActiveSpan(\n name,\n { kind: SpanKind.CLIENT },\n async (span) => {\n span.setAttributes(fetchAttributes(name, url));\n try {\n const headers = buildPropagatedHeaders(input, init);\n const response = await callOriginal(original, input, init, headers);\n span.setAttribute(ATTR_HTTP_RESPONSE_STATUS_CODE, response.status);\n span.setStatus({\n code:\n response.status >= HTTP_ERROR_STATUS_MIN\n ? SpanStatusCode.ERROR\n : SpanStatusCode.OK,\n });\n return response;\n } catch (err) {\n span.recordException(err as Error);\n const errorObj = err instanceof Error ? err : undefined;\n span.setAttribute(\n ATTR_ERROR_TYPE,\n errorObj?.constructor.name ?? typeof err\n );\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: errorObj\n ? sanitizeErrorMessage(errorObj.message)\n : sanitizeErrorMessage(String(err)),\n });\n throw err;\n } finally {\n span.end();\n }\n }\n );\n };\n}\n\n/**\n * Wrap `globalThis.fetch` so every outbound request produces a CLIENT span and\n * carries W3C trace context to the downstream service.\n *\n * On Bun this is the only fetch instrumentation that works: Bun's native fetch\n * emits no `diagnostics_channel` events, so the standard `instrumentation-undici`\n * / `instrumentation-http` (and `opentelemetry-instrumentation-fetch-node`,\n * which is itself diagnostics_channel-based) produce no spans. It works\n * identically on Node, where `globalThis.fetch` is undici-backed.\n *\n * Idempotent: a second call does not stack another wrapper. Returns a handle\n * whose `unpatch()` restores the original fetch.\n */\nexport function instrumentFetch(\n options?: InstrumentFetchOptions\n): FetchInstrumentation {\n const current: FetchFn = globalThis.fetch;\n const existingOriginal = getPatchOriginal(current);\n if (existingOriginal) {\n return {\n unpatch() {\n if (globalThis.fetch === current) {\n setGlobalFetch(existingOriginal);\n }\n },\n };\n }\n\n const original = current;\n const wrapped = buildWrappedFetch(original, options);\n preserveProps(original, wrapped);\n setPatchOriginal(wrapped, original);\n setGlobalFetch(wrapped);\n\n return {\n unpatch() {\n if (globalThis.fetch === wrapped) {\n setGlobalFetch(original);\n }\n },\n };\n}\n","// E.164-ish phone match: optional `+`, 7–15 digits with optional separators.\nconst PHONE_PATTERN = /\\+?\\d[\\d\\s()\\-.]{6,18}\\d/g;\nconst EMAIL_PATTERN = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\\.[A-Za-z]{2,}/g;\n\n/**\n * Mask a phone number, keeping the leading `+` (if any) plus the first 3 digits\n * and the last 4 digits visible. Example: `+13315553374` -> `+133xxxxx3374`.\n *\n * Inputs that don't have enough digits to safely mask are returned as\n * `xxxx` to avoid leaking the entire short value.\n */\nexport function sanitizePhone(input: string): string {\n const hasPlus = input.startsWith(\"+\");\n const digits = input.replace(/\\D/g, \"\");\n if (digits.length < 8) {\n return hasPlus ? \"+xxxx\" : \"xxxx\";\n }\n const head = digits.slice(0, 3);\n const tail = digits.slice(-4);\n const middleLength = digits.length - head.length - tail.length;\n return `${hasPlus ? \"+\" : \"\"}${head}${\"x\".repeat(middleLength)}${tail}`;\n}\n\n/**\n * Mask an email address, keeping the first 2 chars of the local part, the\n * first char of the domain, and the TLD. Example:\n * `foo.bar@example.com` -> `fo***@e***.com`.\n */\nexport function sanitizeEmail(input: string): string {\n const atIndex = input.lastIndexOf(\"@\");\n if (atIndex < 1) {\n return \"***\";\n }\n const local = input.slice(0, atIndex);\n const domain = input.slice(atIndex + 1);\n const dotIndex = domain.lastIndexOf(\".\");\n if (dotIndex < 1) {\n return \"***\";\n }\n const localHead = local.slice(0, 2);\n const domainHead = domain.slice(0, 1);\n const tld = domain.slice(dotIndex);\n return `${localHead}***@${domainHead}***${tld}`;\n}\n\n/**\n * Replace every phone number and email address inside a free-form string with\n * its sanitized form. Used to scrub `Error.message` values before attaching\n * them to span status.\n */\nexport function sanitizeErrorMessage(input: string): string {\n return input\n .replace(EMAIL_PATTERN, (match) => sanitizeEmail(match))\n .replace(PHONE_PATTERN, (match) => sanitizePhone(match));\n}\n","export const PHOTON_OTEL_VERSION = \"0.1.0\";\n","import { context as otelContext } from \"@opentelemetry/api\";\nimport { type Logger, logs, SeverityNumber } from \"@opentelemetry/api-logs\";\nimport { PHOTON_OTEL_VERSION } from \"./version\";\n\nexport type LogAttrs = Record<string, string | number | boolean | undefined>;\n\n/**\n * Minimum severity that gets emitted (to both the OTLP record and the console).\n * `\"silent\"` suppresses everything, including errors.\n */\nexport type LogLevel = \"debug\" | \"info\" | \"warn\" | \"error\" | \"silent\";\n\nconst LEVEL_SEVERITY: Record<LogLevel, number> = {\n debug: SeverityNumber.DEBUG, // 5\n info: SeverityNumber.INFO, // 9\n warn: SeverityNumber.WARN, // 13\n error: SeverityNumber.ERROR, // 17\n silent: Number.POSITIVE_INFINITY,\n};\n\nlet levelOverride: LogLevel | undefined;\n\nfunction envLevel(): LogLevel | undefined {\n const raw = process.env.LOG_LEVEL?.toLowerCase();\n if (raw && raw in LEVEL_SEVERITY) {\n return raw as LogLevel;\n }\n return;\n}\n\nfunction defaultLevel(): LogLevel {\n return (process.env.DEPLOYMENT_ENV ?? \"development\") === \"development\"\n ? \"debug\"\n : \"info\";\n}\n\n/**\n * Resolve the active level fresh on each call so that `LOG_LEVEL` changes and\n * `setLogLevel()` both take effect immediately. Resolution order (env wins, to\n * match the rest of the package's config story):\n * 1. `LOG_LEVEL` env var\n * 2. `setLogLevel()` / `setupOtel({ logLevel })`\n * 3. environment-driven default (`debug` in development, `info` otherwise)\n */\nfunction resolveLevel(): LogLevel {\n return envLevel() ?? levelOverride ?? defaultLevel();\n}\n\n/**\n * Programmatically set the minimum log level. Takes effect immediately for\n * subsequent logs. `LOG_LEVEL` env var still wins if set.\n */\nexport function setLogLevel(level: LogLevel): void {\n levelOverride = level;\n}\n\n/** Current effective log level, after env / override / default resolution. */\nexport function getLogLevel(): LogLevel {\n return resolveLevel();\n}\n\nlet scopedLogger: Logger | undefined;\n\nfunction getLogger(): Logger {\n if (!scopedLogger) {\n scopedLogger = logs.getLogger(\"@photon-ai/otel\", PHOTON_OTEL_VERSION);\n }\n return scopedLogger;\n}\n\nfunction filterUndefined(\n attrs?: LogAttrs\n): Record<string, string | number | boolean> {\n if (!attrs) {\n return {};\n }\n const out: Record<string, string | number | boolean> = {};\n for (const [k, v] of Object.entries(attrs)) {\n if (v !== undefined) {\n out[k] = v;\n }\n }\n return out;\n}\n\nfunction consoleFor(\n severityNumber: SeverityNumber\n): (...args: unknown[]) => void {\n if (severityNumber >= SeverityNumber.ERROR) {\n return console.error;\n }\n if (severityNumber >= SeverityNumber.WARN) {\n return console.warn;\n }\n if (severityNumber >= SeverityNumber.INFO) {\n return console.info;\n }\n return console.debug;\n}\n\nfunction emit(\n severityNumber: SeverityNumber,\n severityText: string,\n module: string,\n message: string,\n attrs?: LogAttrs,\n error?: unknown\n): void {\n // Single gate: drop sub-threshold logs before they reach OTLP or the console.\n if (severityNumber < LEVEL_SEVERITY[resolveLevel()]) {\n return;\n }\n\n const userAttrs = filterUndefined(attrs);\n const attributes: Record<string, string | number | boolean> = {\n \"log.module\": module,\n ...userAttrs,\n };\n\n if (error instanceof Error) {\n attributes[\"exception.type\"] = error.name;\n attributes[\"exception.message\"] = error.message;\n if (error.stack) {\n attributes[\"exception.stacktrace\"] = error.stack;\n }\n } else if (error !== undefined) {\n // Don't silently drop non-Error throws (strings, plain objects, etc.).\n attributes[\"exception.type\"] = typeof error;\n attributes[\"exception.message\"] = String(error);\n }\n\n getLogger().emit({\n severityNumber,\n severityText,\n body: message,\n attributes,\n context: otelContext.active(),\n });\n\n // Console: `[module] LEVEL message { ...attrs }` plus the raw error so the\n // runtime renders the full stack and pretty-prints the attribute bag.\n const extras: unknown[] = [];\n if (Object.keys(userAttrs).length > 0) {\n extras.push(userAttrs);\n }\n if (error !== undefined) {\n extras.push(error);\n }\n consoleFor(severityNumber)(`[${module}]`, severityText, message, ...extras);\n}\n\nexport interface PhotonLogger {\n debug(message: string, attrs?: LogAttrs, error?: unknown): void;\n error(message: string, attrs?: LogAttrs, error?: unknown): void;\n info(message: string, attrs?: LogAttrs, error?: unknown): void;\n warn(message: string, attrs?: LogAttrs, error?: unknown): void;\n}\n\nexport function createLogger(module: string): PhotonLogger {\n return {\n debug: (message, attrs, error) =>\n emit(SeverityNumber.DEBUG, \"DEBUG\", module, message, attrs, error),\n info: (message, attrs, error) =>\n emit(SeverityNumber.INFO, \"INFO\", module, message, attrs, error),\n warn: (message, attrs, error) =>\n emit(SeverityNumber.WARN, \"WARN\", module, message, attrs, error),\n error: (message, attrs, error) =>\n emit(SeverityNumber.ERROR, \"ERROR\", module, message, attrs, error),\n };\n}\n","import { context, propagation, trace } from \"@opentelemetry/api\";\nimport { logs } from \"@opentelemetry/api-logs\";\nimport { AsyncLocalStorageContextManager } from \"@opentelemetry/context-async-hooks\";\nimport {\n CompositePropagator,\n W3CBaggagePropagator,\n W3CTraceContextPropagator,\n} from \"@opentelemetry/core\";\nimport { OTLPLogExporter } from \"@opentelemetry/exporter-logs-otlp-http\";\nimport { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-http\";\nimport { resourceFromAttributes } from \"@opentelemetry/resources\";\nimport {\n BatchLogRecordProcessor,\n LoggerProvider,\n} from \"@opentelemetry/sdk-logs\";\nimport {\n BasicTracerProvider,\n BatchSpanProcessor,\n} from \"@opentelemetry/sdk-trace-base\";\nimport {\n type FetchInstrumentation,\n type InstrumentFetchOptions,\n instrumentFetch,\n} from \"./instrument-fetch\";\nimport { type LogLevel, setLogLevel } from \"./logger\";\n\nexport interface SetupOtelOptions {\n /**\n * Default OTLP/HTTP base endpoint (e.g. `https://otel.example.com`). The\n * `/v1/traces` and `/v1/logs` paths are appended automatically. Standard\n * `OTEL_EXPORTER_OTLP_*` env vars always take precedence.\n */\n endpoint?: string;\n /**\n * Default OTLP headers (e.g. `{ Authorization: \"Basic ...\" }`). Merged with\n * any headers parsed from `OTEL_EXPORTER_OTLP_HEADERS`; env values win on\n * conflicts.\n */\n headers?: Record<string, string>;\n /**\n * Auto-instrument outbound `globalThis.fetch` with CLIENT spans and W3C\n * trace-context propagation. On Bun this is the only fetch instrumentation\n * that works (diagnostics_channel-based instrumentations emit nothing on\n * Bun's native fetch); it works identically on Node.\n *\n * `true` enables with defaults; pass an object to filter URLs via `ignore`.\n * Defaults to enabled when a traces endpoint is configured. Pass `false` to\n * disable.\n */\n instrumentFetch?: boolean | InstrumentFetchOptions;\n /**\n * Minimum log level emitted by `createLogger()` (to both OTLP and console).\n * The `LOG_LEVEL` env var still takes precedence. Defaults to `debug` in\n * development and `info` otherwise.\n */\n logLevel?: LogLevel;\n /**\n * Extra resource attributes attached to every span/log alongside\n * `service.name` / `service.version`.\n */\n resourceAttributes?: Record<string, string | number | boolean>;\n serviceName: string;\n serviceVersion?: string;\n}\n\nexport interface OtelHandle {\n shutdown(): Promise<void>;\n}\n\nlet activeHandle: OtelHandle | undefined;\n\nconst TRAILING_SLASH = /\\/$/;\n\nfunction parseEnvHeaders(raw: string | undefined): Record<string, string> {\n if (!raw) {\n return {};\n }\n const out: Record<string, string> = {};\n for (const pair of raw.split(\",\")) {\n const eq = pair.indexOf(\"=\");\n if (eq <= 0) {\n continue;\n }\n const key = pair.slice(0, eq).trim();\n const value = pair.slice(eq + 1).trim();\n if (key) {\n out[key] = value;\n }\n }\n return out;\n}\n\nfunction resolveTracesEndpoint(base: string | undefined): string | undefined {\n const traces = process.env.OTEL_EXPORTER_OTLP_TRACES_ENDPOINT;\n if (traces) {\n return traces;\n }\n const generic = process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? base;\n return generic\n ? `${generic.replace(TRAILING_SLASH, \"\")}/v1/traces`\n : undefined;\n}\n\nfunction resolveLogsEndpoint(base: string | undefined): string | undefined {\n const logsEndpoint = process.env.OTEL_EXPORTER_OTLP_LOGS_ENDPOINT;\n if (logsEndpoint) {\n return logsEndpoint;\n }\n const generic = process.env.OTEL_EXPORTER_OTLP_ENDPOINT ?? base;\n return generic ? `${generic.replace(TRAILING_SLASH, \"\")}/v1/logs` : undefined;\n}\n\n/**\n * Normalize a URL to an `origin + path` key (trailing slash stripped) for exact\n * self-trace matching. Returns `undefined` for unparseable URLs.\n */\nfunction otlpEndpointKey(url: string): string | undefined {\n try {\n const parsed = new URL(url);\n return `${parsed.origin}${parsed.pathname.replace(TRAILING_SLASH, \"\")}`;\n } catch {\n return;\n }\n}\n\nfunction otlpEndpointKeysOf(\n tracesEndpoint: string | undefined,\n logsEndpoint: string | undefined\n): string[] {\n const keys: string[] = [];\n for (const endpoint of [tracesEndpoint, logsEndpoint]) {\n if (!endpoint) {\n continue;\n }\n const key = otlpEndpointKey(endpoint);\n if (key) {\n keys.push(key);\n }\n }\n return keys;\n}\n\n/**\n * Patch `globalThis.fetch` unless disabled. Defaults to on when a traces\n * pipeline is configured. Always excludes our own OTLP endpoints so the\n * exporter's traffic is never self-traced (matters on Node, where the OTLP\n * exporter can use fetch).\n */\nfunction startFetchInstrumentation(\n option: boolean | InstrumentFetchOptions | undefined,\n hasTraces: boolean,\n tracesEndpoint: string | undefined,\n logsEndpoint: string | undefined\n): FetchInstrumentation | undefined {\n const want = option ?? hasTraces;\n if (!want) {\n return;\n }\n const userOptions = typeof option === \"object\" ? option : undefined;\n const otlpEndpointKeys = otlpEndpointKeysOf(tracesEndpoint, logsEndpoint);\n return instrumentFetch({\n ignore: (url) => {\n const key = otlpEndpointKey(url);\n const isOtlpEndpoint =\n key !== undefined && otlpEndpointKeys.includes(key);\n return isOtlpEndpoint || (userOptions?.ignore?.(url) ?? false);\n },\n });\n}\n\n/**\n * Boot an OTLP/HTTP-based OpenTelemetry pipeline (traces + logs).\n *\n * Idempotent: calling twice in the same process is a no-op on the second\n * call, so libraries can safely invoke this without clobbering an app-level\n * OTel setup that ran earlier.\n *\n * Standard `OTEL_EXPORTER_OTLP_*` env vars override the `endpoint` and\n * `headers` arguments — this matches the OpenTelemetry SDK config spec.\n */\nexport function setupOtel(options: SetupOtelOptions): OtelHandle {\n if (activeHandle) {\n return activeHandle;\n }\n\n if (options.logLevel) {\n setLogLevel(options.logLevel);\n }\n\n const tracesEndpoint = resolveTracesEndpoint(options.endpoint);\n const logsEndpoint = resolveLogsEndpoint(options.endpoint);\n const mergedHeaders = {\n ...options.headers,\n ...parseEnvHeaders(process.env.OTEL_EXPORTER_OTLP_HEADERS),\n };\n const hasHeaders = Object.keys(mergedHeaders).length > 0;\n\n const resource = resourceFromAttributes({\n \"service.name\": options.serviceName,\n ...(options.serviceVersion\n ? { \"service.version\": options.serviceVersion }\n : {}),\n \"deployment.environment\": process.env.DEPLOYMENT_ENV ?? \"development\",\n ...options.resourceAttributes,\n });\n\n context.setGlobalContextManager(new AsyncLocalStorageContextManager());\n propagation.setGlobalPropagator(\n new CompositePropagator({\n propagators: [\n new W3CTraceContextPropagator(),\n new W3CBaggagePropagator(),\n ],\n })\n );\n\n const traceProcessors = tracesEndpoint\n ? [\n new BatchSpanProcessor(\n new OTLPTraceExporter({\n url: tracesEndpoint,\n headers: hasHeaders ? mergedHeaders : undefined,\n })\n ),\n ]\n : [];\n\n const tracerProvider = new BasicTracerProvider({\n resource,\n spanProcessors: traceProcessors,\n });\n trace.setGlobalTracerProvider(tracerProvider);\n\n const fetchInstrumentation = startFetchInstrumentation(\n options.instrumentFetch,\n traceProcessors.length > 0,\n tracesEndpoint,\n logsEndpoint\n );\n\n const logProcessors = logsEndpoint\n ? [\n new BatchLogRecordProcessor(\n new OTLPLogExporter({\n url: logsEndpoint,\n headers: hasHeaders ? mergedHeaders : undefined,\n })\n ),\n ]\n : [];\n\n const loggerProvider = new LoggerProvider({\n resource,\n processors: logProcessors,\n });\n logs.setGlobalLoggerProvider(loggerProvider);\n\n const handle: OtelHandle = {\n async shutdown() {\n fetchInstrumentation?.unpatch();\n await Promise.allSettled([\n tracerProvider.shutdown(),\n loggerProvider.shutdown(),\n ]);\n activeHandle = undefined;\n },\n };\n\n activeHandle = handle;\n return handle;\n}\n\n/**\n * Read-only accessor for tests / debug paths that need to know whether\n * `setupOtel` has already run in this process.\n */\nexport function isOtelActive(): boolean {\n return activeHandle !== undefined;\n}\n","import {\n type Attributes,\n SpanStatusCode,\n type Tracer,\n trace,\n} from \"@opentelemetry/api\";\nimport type { LogAttrs } from \"./logger\";\nimport { sanitizeErrorMessage } from \"./sanitize\";\nimport { PHOTON_OTEL_VERSION } from \"./version\";\n\nlet scopedTracer: Tracer | undefined;\n\nfunction getTracer(): Tracer {\n if (!scopedTracer) {\n scopedTracer = trace.getTracer(\"@photon-ai/otel\", PHOTON_OTEL_VERSION);\n }\n return scopedTracer;\n}\n\nfunction toAttributes(attrs: LogAttrs): Attributes {\n const out: Attributes = {};\n for (const [k, v] of Object.entries(attrs)) {\n if (v !== undefined) {\n out[k] = v;\n }\n }\n return out;\n}\n\nexport function withSpan<T>(name: string, fn: () => Promise<T> | T): Promise<T>;\nexport function withSpan<T>(\n name: string,\n attrs: LogAttrs,\n fn: () => Promise<T> | T\n): Promise<T>;\nexport function withSpan<T>(\n name: string,\n attrsOrFn: LogAttrs | (() => Promise<T> | T),\n maybeFn?: () => Promise<T> | T\n): Promise<T> {\n const fn = typeof attrsOrFn === \"function\" ? attrsOrFn : maybeFn;\n if (!fn) {\n throw new Error(\"withSpan: function argument is required\");\n }\n const attrs = typeof attrsOrFn === \"function\" ? undefined : attrsOrFn;\n\n return getTracer().startActiveSpan(name, async (span) => {\n if (attrs) {\n span.setAttributes(toAttributes(attrs));\n }\n try {\n const result = await fn();\n span.setStatus({ code: SpanStatusCode.OK });\n return result;\n } catch (err) {\n span.recordException(err as Error);\n const errorObj = err instanceof Error ? err : undefined;\n span.setAttribute(\"error.type\", errorObj?.constructor.name ?? typeof err);\n span.setStatus({\n code: SpanStatusCode.ERROR,\n message: errorObj\n ? sanitizeErrorMessage(errorObj.message)\n : sanitizeErrorMessage(String(err)),\n });\n throw err;\n } finally {\n span.end();\n }\n });\n}\n"],"mappings":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B,OAAO,GAAG,CAAC;AAAA,MACtC,CAAC;AACD,YAAM;AAAA,IACR,UAAE;AACA,WAAK,IAAI;AAAA,IACX;AAAA,EACF,CAAC;AACH;","names":["context","propagation","trace","logs","context","propagation","trace","logs","SpanStatusCode","trace","scopedTracer","getTracer","trace","toAttributes","SpanStatusCode"]}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@photon-ai/otel",
|
|
3
|
-
"version": "
|
|
3
|
+
"version": "1.1.0",
|
|
4
4
|
"description": "DX-focused OpenTelemetry wrapper for Bun and Node.js: one-call setup, structured logging, span helper, and built-in PII scrubbing.",
|
|
5
5
|
"type": "module",
|
|
6
6
|
"main": "./dist/index.js",
|
|
@@ -20,11 +20,13 @@
|
|
|
20
20
|
"@opentelemetry/api": "^1.9.1",
|
|
21
21
|
"@opentelemetry/api-logs": "^0.218.0",
|
|
22
22
|
"@opentelemetry/context-async-hooks": "^2.7.1",
|
|
23
|
+
"@opentelemetry/core": "^2.7.1",
|
|
23
24
|
"@opentelemetry/exporter-logs-otlp-http": "^0.218.0",
|
|
24
25
|
"@opentelemetry/exporter-trace-otlp-http": "^0.218.0",
|
|
25
26
|
"@opentelemetry/resources": "^2.7.1",
|
|
26
27
|
"@opentelemetry/sdk-logs": "^0.218.0",
|
|
27
|
-
"@opentelemetry/sdk-trace-base": "^2.7.1"
|
|
28
|
+
"@opentelemetry/sdk-trace-base": "^2.7.1",
|
|
29
|
+
"@opentelemetry/semantic-conventions": "^1.41.1"
|
|
28
30
|
},
|
|
29
31
|
"peerDependencies": {
|
|
30
32
|
"typescript": "^5 || ^6.0.0"
|