@reliantlabs/forge-web-runtime 0.3.1 → 0.4.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/dist/otel.js DELETED
@@ -1,94 +0,0 @@
1
- // Part of @reliantlabs/forge-web-runtime — the web twin of forge/pkg.
2
- //
3
- // OpenTelemetry JS SDK 2.x wiring for the browser: a WebTracerProvider with
4
- // a batched OTLP/HTTP exporter, W3C trace-context propagation, and the fetch
5
- // / XHR / document-load auto-instrumentations.
6
- //
7
- // This is the EXPORT path. Distributed tracing itself — the traceparent
8
- // attached to every RPC, which is what makes browser spans join the backend's
9
- // trace — is always on and lives in trace.ts; it needs no collector and does
10
- // NOT depend on this module. Reach for this when you additionally want the
11
- // browser's own spans shipped somewhere.
12
- //
13
- // Imported through the "@reliantlabs/forge-web-runtime/otel" subpath, never the
14
- // barrel. The eight @opentelemetry/* SDK packages below are heavy, and only
15
- // the Next.js scaffold installs them: a Vite SPA or React Native frontend
16
- // declares just @opentelemetry/api and imports the barrel, so re-exporting
17
- // this from index.ts would leave those frontends resolving packages they
18
- // never installed.
19
- //
20
- // Notable migration points from SDK 1.x -> 2.x:
21
- // - `new Resource({ ... })` is replaced by `resourceFromAttributes({ ... })`.
22
- // The `Resource` class is no longer exported from `@opentelemetry/resources`.
23
- // - `provider.addSpanProcessor(...)` is removed; span processors must be
24
- // passed via the `spanProcessors` option on the `WebTracerProvider`
25
- // constructor (the provider becomes immutable after construction).
26
- // - Minimum TS target is ES2022.
27
- //
28
- // See https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md
29
- import { context, propagation, trace } from "@opentelemetry/api";
30
- import { getWebAutoInstrumentations } from "@opentelemetry/auto-instrumentations-web";
31
- import { W3CTraceContextPropagator } from "@opentelemetry/core";
32
- import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-http";
33
- import { registerInstrumentations } from "@opentelemetry/instrumentation";
34
- import { resourceFromAttributes } from "@opentelemetry/resources";
35
- import { BatchSpanProcessor } from "@opentelemetry/sdk-trace-base";
36
- import { WebTracerProvider } from "@opentelemetry/sdk-trace-web";
37
- import { ATTR_SERVICE_NAME, ATTR_SERVICE_VERSION, } from "@opentelemetry/semantic-conventions";
38
- let provider = null;
39
- /**
40
- * initBrowserTracing registers the browser tracer provider and the fetch /
41
- * XHR / document-load auto-instrumentations.
42
- *
43
- * No-ops without an `endpoint` (nothing to export to) and without a DOM
44
- * (SSR / prerender). Idempotent: a second call while a provider is already
45
- * registered returns without double-registering, which is what survives
46
- * React StrictMode's double-mount and Fast Refresh.
47
- *
48
- * The env vars that carry the endpoint stay in APPLICATION code
49
- * (`NEXT_PUBLIC_OTEL_ENDPOINT` and friends) — a bundler replaces those
50
- * literals at build time, and it can only do that where they are written
51
- * out verbatim.
52
- */
53
- export function initBrowserTracing(config) {
54
- if (!config.endpoint || typeof window === "undefined") {
55
- return; // No-op when endpoint not configured or SSR
56
- }
57
- if (provider) {
58
- return; // Idempotent — avoid double-registering on HMR/StrictMode remounts
59
- }
60
- const resource = resourceFromAttributes({
61
- [ATTR_SERVICE_NAME]: config.serviceName,
62
- [ATTR_SERVICE_VERSION]: config.serviceVersion || "0.0.0",
63
- });
64
- provider = new WebTracerProvider({
65
- resource,
66
- spanProcessors: [
67
- new BatchSpanProcessor(new OTLPTraceExporter({
68
- url: `${config.endpoint}/v1/traces`,
69
- })),
70
- ],
71
- });
72
- // Enable W3C trace context propagation (sends traceparent header)
73
- propagation.setGlobalPropagator(new W3CTraceContextPropagator());
74
- provider.register();
75
- // Auto-instrument fetch, XMLHttpRequest, document load
76
- registerInstrumentations({
77
- instrumentations: [
78
- getWebAutoInstrumentations({
79
- "@opentelemetry/instrumentation-fetch": {
80
- propagateTraceHeaderCorsUrls: [/.*/], // Propagate to all URLs
81
- },
82
- "@opentelemetry/instrumentation-xml-http-request": {
83
- propagateTraceHeaderCorsUrls: [/.*/],
84
- },
85
- }),
86
- ],
87
- });
88
- }
89
- /** The tracer to open manual spans on. */
90
- export function getTracer(name = "default") {
91
- return trace.getTracer(name);
92
- }
93
- export { context, propagation, trace };
94
- //# sourceMappingURL=otel.js.map
package/dist/otel.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"otel.js","sourceRoot":"","sources":["../src/otel.ts"],"names":[],"mappings":"AAAA,sEAAsE;AACtE,EAAE;AACF,4EAA4E;AAC5E,6EAA6E;AAC7E,+CAA+C;AAC/C,EAAE;AACF,wEAAwE;AACxE,8EAA8E;AAC9E,6EAA6E;AAC7E,2EAA2E;AAC3E,yCAAyC;AACzC,EAAE;AACF,gFAAgF;AAChF,4EAA4E;AAC5E,0EAA0E;AAC1E,2EAA2E;AAC3E,yEAAyE;AACzE,mBAAmB;AACnB,EAAE;AACF,gDAAgD;AAChD,gFAAgF;AAChF,kFAAkF;AAClF,2EAA2E;AAC3E,wEAAwE;AACxE,uEAAuE;AACvE,mCAAmC;AACnC,EAAE;AACF,yFAAyF;AACzF,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AACjE,OAAO,EAAE,0BAA0B,EAAE,MAAM,0CAA0C,CAAC;AACtF,OAAO,EAAE,yBAAyB,EAAE,MAAM,qBAAqB,CAAC;AAChE,OAAO,EAAE,iBAAiB,EAAE,MAAM,yCAAyC,CAAC;AAC5E,OAAO,EAAE,wBAAwB,EAAE,MAAM,gCAAgC,CAAC;AAC1E,OAAO,EAAE,sBAAsB,EAAE,MAAM,0BAA0B,CAAC;AAClE,OAAO,EAAE,kBAAkB,EAAE,MAAM,+BAA+B,CAAC;AACnE,OAAO,EAAE,iBAAiB,EAAE,MAAM,8BAA8B,CAAC;AACjE,OAAO,EACL,iBAAiB,EACjB,oBAAoB,GACrB,MAAM,qCAAqC,CAAC;AAe7C,IAAI,QAAQ,GAA6B,IAAI,CAAC;AAE9C;;;;;;;;;;;;;GAaG;AACH,MAAM,UAAU,kBAAkB,CAAC,MAA4B;IAC7D,IAAI,CAAC,MAAM,CAAC,QAAQ,IAAI,OAAO,MAAM,KAAK,WAAW,EAAE,CAAC;QACtD,OAAO,CAAC,4CAA4C;IACtD,CAAC;IACD,IAAI,QAAQ,EAAE,CAAC;QACb,OAAO,CAAC,mEAAmE;IAC7E,CAAC;IAED,MAAM,QAAQ,GAAG,sBAAsB,CAAC;QACtC,CAAC,iBAAiB,CAAC,EAAE,MAAM,CAAC,WAAW;QACvC,CAAC,oBAAoB,CAAC,EAAE,MAAM,CAAC,cAAc,IAAI,OAAO;KACzD,CAAC,CAAC;IAEH,QAAQ,GAAG,IAAI,iBAAiB,CAAC;QAC/B,QAAQ;QACR,cAAc,EAAE;YACd,IAAI,kBAAkB,CACpB,IAAI,iBAAiB,CAAC;gBACpB,GAAG,EAAE,GAAG,MAAM,CAAC,QAAQ,YAAY;aACpC,CAAC,CACH;SACF;KACF,CAAC,CAAC;IAEH,kEAAkE;IAClE,WAAW,CAAC,mBAAmB,CAAC,IAAI,yBAAyB,EAAE,CAAC,CAAC;IACjE,QAAQ,CAAC,QAAQ,EAAE,CAAC;IAEpB,uDAAuD;IACvD,wBAAwB,CAAC;QACvB,gBAAgB,EAAE;YAChB,0BAA0B,CAAC;gBACzB,sCAAsC,EAAE;oBACtC,4BAA4B,EAAE,CAAC,IAAI,CAAC,EAAE,wBAAwB;iBAC/D;gBACD,iDAAiD,EAAE;oBACjD,4BAA4B,EAAE,CAAC,IAAI,CAAC;iBACrC;aACF,CAAC;SACH;KACF,CAAC,CAAC;AACL,CAAC;AAED,0CAA0C;AAC1C,MAAM,UAAU,SAAS,CAAC,IAAI,GAAG,SAAS;IACxC,OAAO,KAAK,CAAC,SAAS,CAAC,IAAI,CAAC,CAAC;AAC/B,CAAC;AAED,OAAO,EAAE,OAAO,EAAE,WAAW,EAAE,KAAK,EAAE,CAAC","sourcesContent":["// Part of @reliantlabs/forge-web-runtime — the web twin of forge/pkg.\n//\n// OpenTelemetry JS SDK 2.x wiring for the browser: a WebTracerProvider with\n// a batched OTLP/HTTP exporter, W3C trace-context propagation, and the fetch\n// / XHR / document-load auto-instrumentations.\n//\n// This is the EXPORT path. Distributed tracing itself — the traceparent\n// attached to every RPC, which is what makes browser spans join the backend's\n// trace — is always on and lives in trace.ts; it needs no collector and does\n// NOT depend on this module. Reach for this when you additionally want the\n// browser's own spans shipped somewhere.\n//\n// Imported through the \"@reliantlabs/forge-web-runtime/otel\" subpath, never the\n// barrel. The eight @opentelemetry/* SDK packages below are heavy, and only\n// the Next.js scaffold installs them: a Vite SPA or React Native frontend\n// declares just @opentelemetry/api and imports the barrel, so re-exporting\n// this from index.ts would leave those frontends resolving packages they\n// never installed.\n//\n// Notable migration points from SDK 1.x -> 2.x:\n// - `new Resource({ ... })` is replaced by `resourceFromAttributes({ ... })`.\n// The `Resource` class is no longer exported from `@opentelemetry/resources`.\n// - `provider.addSpanProcessor(...)` is removed; span processors must be\n// passed via the `spanProcessors` option on the `WebTracerProvider`\n// constructor (the provider becomes immutable after construction).\n// - Minimum TS target is ES2022.\n//\n// See https://github.com/open-telemetry/opentelemetry-js/blob/main/doc/upgrade-to-2.x.md\nimport { context, propagation, trace } from \"@opentelemetry/api\";\nimport { getWebAutoInstrumentations } from \"@opentelemetry/auto-instrumentations-web\";\nimport { W3CTraceContextPropagator } from \"@opentelemetry/core\";\nimport { OTLPTraceExporter } from \"@opentelemetry/exporter-trace-otlp-http\";\nimport { registerInstrumentations } from \"@opentelemetry/instrumentation\";\nimport { resourceFromAttributes } from \"@opentelemetry/resources\";\nimport { BatchSpanProcessor } from \"@opentelemetry/sdk-trace-base\";\nimport { WebTracerProvider } from \"@opentelemetry/sdk-trace-web\";\nimport {\n ATTR_SERVICE_NAME,\n ATTR_SERVICE_VERSION,\n} from \"@opentelemetry/semantic-conventions\";\n\nexport interface BrowserTracingConfig {\n /**\n * Collector base URL. Spans are POSTed to `${endpoint}/v1/traces`. Unset or\n * empty is a no-op — the app runs untraced rather than throwing, which is\n * what makes this safe to call unconditionally from the app shell.\n */\n endpoint?: string;\n /** `service.name` on every span. */\n serviceName: string;\n /** `service.version` on every span. Defaults to \"0.0.0\". */\n serviceVersion?: string;\n}\n\nlet provider: WebTracerProvider | null = null;\n\n/**\n * initBrowserTracing registers the browser tracer provider and the fetch /\n * XHR / document-load auto-instrumentations.\n *\n * No-ops without an `endpoint` (nothing to export to) and without a DOM\n * (SSR / prerender). Idempotent: a second call while a provider is already\n * registered returns without double-registering, which is what survives\n * React StrictMode's double-mount and Fast Refresh.\n *\n * The env vars that carry the endpoint stay in APPLICATION code\n * (`NEXT_PUBLIC_OTEL_ENDPOINT` and friends) — a bundler replaces those\n * literals at build time, and it can only do that where they are written\n * out verbatim.\n */\nexport function initBrowserTracing(config: BrowserTracingConfig): void {\n if (!config.endpoint || typeof window === \"undefined\") {\n return; // No-op when endpoint not configured or SSR\n }\n if (provider) {\n return; // Idempotent — avoid double-registering on HMR/StrictMode remounts\n }\n\n const resource = resourceFromAttributes({\n [ATTR_SERVICE_NAME]: config.serviceName,\n [ATTR_SERVICE_VERSION]: config.serviceVersion || \"0.0.0\",\n });\n\n provider = new WebTracerProvider({\n resource,\n spanProcessors: [\n new BatchSpanProcessor(\n new OTLPTraceExporter({\n url: `${config.endpoint}/v1/traces`,\n }),\n ),\n ],\n });\n\n // Enable W3C trace context propagation (sends traceparent header)\n propagation.setGlobalPropagator(new W3CTraceContextPropagator());\n provider.register();\n\n // Auto-instrument fetch, XMLHttpRequest, document load\n registerInstrumentations({\n instrumentations: [\n getWebAutoInstrumentations({\n \"@opentelemetry/instrumentation-fetch\": {\n propagateTraceHeaderCorsUrls: [/.*/], // Propagate to all URLs\n },\n \"@opentelemetry/instrumentation-xml-http-request\": {\n propagateTraceHeaderCorsUrls: [/.*/],\n },\n }),\n ],\n });\n}\n\n/** The tracer to open manual spans on. */\nexport function getTracer(name = \"default\") {\n return trace.getTracer(name);\n}\n\nexport { context, propagation, trace };\n"]}