@@ -13,19 +13,20 @@ const gac = Deno.env.get('GOOGLE_APPLICATION_CREDENTIALS');
1313const sa = await ( gac
1414 ? ServiceAccount . readFromFile ( gac )
1515 : ServiceAccount . loadFromJson ( { type : 'metadata_service_account' } ) ) ;
16+ const projectId = await sa . getProjectId ( ) ;
1617const token = await sa . issueToken ( [ 'https://www.googleapis.com/auth/cloud-platform' ] ) ;
1718
1819export async function sendSpans ( traceId : string , spans : GcpSpan [ ] ) {
19- console . log ( spans )
20- const resp = await fetch ( `https://cloudtrace.googleapis.com/v2/projects/${ await sa . getProjectId ( ) } /traces:batchWrite` , {
20+ console . log ( JSON . stringify ( spans ) )
21+ const resp = await fetch ( `https://cloudtrace.googleapis.com/v2/projects/${ projectId } /traces:batchWrite` , {
2122 method : 'POST' ,
2223 headers : {
2324 'content-type' : 'application/json' ,
2425 'authorization' : `Bearer ${ token . accessToken } ` ,
2526 } ,
2627 body : JSON . stringify ( {
2728 "spans" : spans . map ( span => ( {
28- "name" : `projects/dist-app-v1alpha1 /traces/${ traceId } /spans/${ span . spanId } ` ,
29+ "name" : `projects/${ projectId } /traces/${ traceId } /spans/${ span . spanId } ` ,
2930 ...span ,
3031 } ) ) ,
3132 } ) ,
@@ -154,6 +155,7 @@ class TraceContext {
154155// deno 1.31 adds this, with a generic type parameter even
155156// import { AsyncLocalStorage } from "node:async_hooks";
156157import { AsyncLocalStorage } from "node:async_hooks" ;
158+ import { http } from "./deps.ts" ;
157159const asyncLocalStorage = new AsyncLocalStorage ( ) ;
158160
159161export function runWithNewTraceContext < T extends unknown > ( func : ( ) => Promise < T > ) : Promise < T > {
0 commit comments