@obtrace/browser 2.3.0 → 2.4.1

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.
@@ -14,6 +14,7 @@ import { DocumentLoadInstrumentation } from "@opentelemetry/instrumentation-docu
14
14
  import { UserInteractionInstrumentation } from "@opentelemetry/instrumentation-user-interaction";
15
15
  import { ZoneContextManager } from "@opentelemetry/context-zone";
16
16
  import { registerInstrumentations } from "@opentelemetry/instrumentation";
17
+ import { enrichSupabaseSpan, isSupabaseURL } from "../browser/supabase";
17
18
  export function setupOtelWeb(config) {
18
19
  const baseUrl = (config.ingestBaseUrl || "https://ingest.obtrace.ai").replace(/\/$/, "");
19
20
  const authHeaders = {
@@ -74,11 +75,22 @@ export function setupOtelWeb(config) {
74
75
  });
75
76
  const ingestPattern = new RegExp(`^${baseUrl.replace(/[.*+?^${}()|[\]\\]/g, "\\$&")}`);
76
77
  const instrumentations = [];
78
+ const applySupabaseAttrs = (span, req, _result) => {
79
+ try {
80
+ const url = typeof req === "string" ? req : req instanceof URL ? req.href : req?.url || "";
81
+ const method = req?.method || "GET";
82
+ if (url && isSupabaseURL(url)) {
83
+ enrichSupabaseSpan(span, url, method);
84
+ }
85
+ }
86
+ catch { }
87
+ };
77
88
  if (config.instrumentGlobalFetch !== false) {
78
89
  instrumentations.push(new FetchInstrumentation({
79
90
  propagateTraceHeaderCorsUrls: /.*/,
80
91
  ignoreUrls: [ingestPattern],
81
92
  clearTimingResources: true,
93
+ applyCustomAttributesOnSpan: applySupabaseAttrs,
82
94
  }));
83
95
  }
84
96
  if (config.instrumentXHR !== false) {
@@ -94,8 +106,8 @@ export function setupOtelWeb(config) {
94
106
  tracerProvider,
95
107
  instrumentations,
96
108
  });
97
- const tracer = trace.getTracer("@obtrace/sdk-browser", "2.2.0");
98
- const meter = metrics.getMeter("@obtrace/sdk-browser", "2.2.0");
109
+ const tracer = trace.getTracer("@obtrace/sdk-browser", "2.4.0");
110
+ const meter = metrics.getMeter("@obtrace/sdk-browser", "2.4.0");
99
111
  const forceFlush = async () => {
100
112
  try {
101
113
  await tracerProvider.forceFlush();
@@ -0,0 +1,2 @@
1
+ import { type Tracer } from "@opentelemetry/api";
2
+ export declare function installSupabaseFetchInterceptor(tracer: Tracer, sessionId: string): () => void;
@@ -0,0 +1,12 @@
1
+ import { type Span } from "@opentelemetry/api";
2
+ interface SupabaseParsed {
3
+ ref: string;
4
+ service: string;
5
+ operation: string;
6
+ table: string;
7
+ detail: string;
8
+ }
9
+ export declare function isSupabaseURL(url: string): boolean;
10
+ export declare function parseSupabaseURL(url: string, method: string): SupabaseParsed | null;
11
+ export declare function enrichSupabaseSpan(span: Span, url: string, method: string): void;
12
+ export {};
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@obtrace/browser",
3
- "version": "2.3.0",
3
+ "version": "2.4.1",
4
4
  "description": "Obtrace Browser SDK with frontend wrappers",
5
5
  "type": "module",
6
6
  "license": "MIT",