File tree Expand file tree Collapse file tree 8 files changed +36
-15
lines changed
Expand file tree Collapse file tree 8 files changed +36
-15
lines changed Original file line number Diff line number Diff line change 8484 "@supabase/functions-js" : " *" ,
8585 "@supabase/postgrest-js" : " *" ,
8686 "@supabase/realtime-js" : " *" ,
87- "@supabase/storage-js" : " *" ,
88- "@supabase/tracing" : " *"
87+ "@supabase/storage-js" : " *"
8988 },
9089 "devDependencies" : {
90+ "@supabase/tracing" : " *" ,
9191 "jsr" : " ^0.13.5" ,
9292 "puppeteer" : " ^24.9.0"
9393 },
Original file line number Diff line number Diff line change @@ -44,7 +44,7 @@ export const fetchWithAuth = (
4444 }
4545
4646 // Inject trace headers
47- const traceHeaders = getTraceHeaders ( input , supabaseUrl , tracePropagationOptions )
47+ const traceHeaders = await getTraceHeaders ( input , supabaseUrl , tracePropagationOptions )
4848
4949 if ( traceHeaders ) {
5050 if ( traceHeaders . traceparent && ! headers . has ( 'traceparent' ) ) {
@@ -70,11 +70,11 @@ export const fetchWithAuth = (
7070 * @param options - Trace propagation options
7171 * @returns Trace context headers, or null if trace propagation is disabled or unavailable
7272 */
73- function getTraceHeaders (
73+ async function getTraceHeaders (
7474 input : RequestInfo | URL ,
7575 supabaseUrl : string ,
7676 options ?: TracePropagationOptions
77- ) : TraceContext | null {
77+ ) : Promise < TraceContext | null > {
7878 // Check if trace propagation is enabled
7979 if ( options ?. enabled === false ) {
8080 return null
@@ -93,7 +93,7 @@ function getTraceHeaders(
9393 }
9494
9595 // Extract trace context
96- const traceContext = extractTraceContext ( )
96+ const traceContext = await extractTraceContext ( )
9797
9898 if ( ! traceContext || ! traceContext . traceparent ) {
9999 return null
Original file line number Diff line number Diff line change 11import { resolveFetch , resolveHeadersConstructor , fetchWithAuth } from '../../src/lib/fetch'
22
3+ jest . mock ( '@supabase/tracing' , ( ) => {
4+ const actual = jest . requireActual ( '@supabase/tracing' )
5+ return {
6+ ...actual ,
7+ extractTraceContext : jest . fn ( ) . mockResolvedValue ( {
8+ traceparent : '00-0af7651916cd43dd8448eb211c80319c-b7ad6b7169203331-00' ,
9+ } ) ,
10+ }
11+ } )
12+
313// Mock fetch for testing
414const mockFetch = jest . fn ( )
515const mockHeaders = jest . fn ( )
Original file line number Diff line number Diff line change @@ -14,13 +14,15 @@ export default defineConfig([
1414 clean : true ,
1515 outDir : 'dist' ,
1616 // CRITICAL: Keep @supabase /* packages external - not bundled
17+ // NOTE: @supabase /tracing intentionally omitted — it gets bundled via noExternal
1718 external : [
1819 '@supabase/auth-js' ,
1920 '@supabase/functions-js' ,
2021 '@supabase/postgrest-js' ,
2122 '@supabase/realtime-js' ,
2223 '@supabase/storage-js' ,
2324 ] ,
25+ noExternal : [ '@supabase/tracing' ] ,
2426 fixedExtension : true ,
2527 hash : false ,
2628 target : 'es2017' ,
Original file line number Diff line number Diff line change 55 "main" : " dist/main/index.js" ,
66 "module" : " dist/module/index.js" ,
77 "types" : " dist/module/index.d.ts" ,
8+ "exports" : {
9+ "." : {
10+ "import" : " ./dist/module/index.js" ,
11+ "require" : " ./dist/main/index.js" ,
12+ "types" : " ./dist/module/index.d.ts"
13+ }
14+ },
815 "sideEffects" : false ,
916 "scripts" : {
1017 "build" : " npm run build:main && npm run build:module" ,
Original file line number Diff line number Diff line change @@ -14,12 +14,14 @@ import type { TraceContext } from './types'
1414 * const context = extractTraceContext()
1515 * ```
1616 */
17- export function extractTraceContext ( ) : TraceContext | null {
18- // Try OpenTelemetry API (dynamic require , fails gracefully if not available)
17+ export async function extractTraceContext ( ) : Promise < TraceContext | null > {
18+ // Try OpenTelemetry API (dynamic import , fails gracefully if not available)
1919 try {
20- // Use dynamic require to avoid bundling @opentelemetry /api
21- // This will only work if the user has installed it
22- const otel = require ( '@opentelemetry/api' )
20+ // Use dynamic import to avoid bundling @opentelemetry /api and to prevent
21+ // bundlers from emitting a top-level createRequire(import.meta.url) shim,
22+ // which breaks in Deno when the module is loaded via an https:// URL.
23+ // @ts -ignore - @opentelemetry/api is an optional peer dependency
24+ const otel = await import ( '@opentelemetry/api' )
2325
2426 if ( ! otel || ! otel . propagation || ! otel . context ) {
2527 return null
Original file line number Diff line number Diff line change @@ -2,9 +2,9 @@ import { extractTraceContext } from '../src/extract'
22
33describe ( 'extractTraceContext' , ( ) => {
44 describe ( 'OpenTelemetry API' , ( ) => {
5- it ( 'should return null when OTel API is not available' , ( ) => {
5+ it ( 'should return null when OTel API is not available' , async ( ) => {
66 // Without OpenTelemetry API installed, should return null
7- const result = extractTraceContext ( )
7+ const result = await extractTraceContext ( )
88
99 // Since @opentelemetry /api is not installed in this package, this should return null
1010 expect ( result ) . toBeNull ( )
You can’t perform that action at this time.
0 commit comments