@@ -2,7 +2,7 @@ import { resourceFromAttributes } from "@opentelemetry/resources";
22import { NodeSDK , NodeSDKConfiguration } from "@opentelemetry/sdk-node" ;
33import { VERSION } from "../version" ;
44import { OpenTelemetryKeys } from "./OpenTelemetryKeys" ;
5- import { Tracer , TracerInitializeOptions , TracerOptions } from "./Tracer" ;
5+ import { Tracer , TracerInitializeOptions } from "./Tracer" ;
66import { TracerConfiguration } from "./TracerConfiguration" ;
77
88export type NodeTracerInitializeOptions = TracerInitializeOptions & {
@@ -14,15 +14,16 @@ export class NodeTracer extends Tracer {
1414 private nodeSDK ?: NodeSDK ;
1515
1616 public async initialize (
17- options : NodeTracerInitializeOptions = { } ,
17+ options : NodeTracerInitializeOptions = { }
1818 ) : Promise < NodeTracer > {
1919 if ( this . _initialized ) {
2020 return this ;
2121 }
2222
2323 try {
2424 const resourceAttributes = {
25- [ OpenTelemetryKeys . ResourceKeys . SERVICE_NAME ] : this . projectName ,
25+ [ OpenTelemetryKeys . ResourceKeys . SERVICE_NAME ] :
26+ this . configuration . projectName ,
2627 [ OpenTelemetryKeys . ResourceKeys . TELEMETRY_SDK_VERSION ] : VERSION ,
2728 ...options . resourceAttributes ,
2829 } ;
@@ -35,45 +36,35 @@ export class NodeTracer extends Tracer {
3536
3637 this . nodeSDK . start ( ) ;
3738
38- this . configuration = TracerConfiguration . builder ( )
39- . projectName ( this . projectName )
40- . apiKey ( this . apiKey )
41- . organizationId ( this . organizationId )
42- . enableEvaluation ( this . enableEvaluation )
43- . build ( ) ;
44-
4539 this . _initialized = true ;
4640 return this ;
4741 } catch ( error ) {
4842 throw new Error (
49- `Failed to initialize node tracer: ${ error instanceof Error ? error . message : String ( error ) } ` ,
43+ `Failed to initialize node tracer: ${ error instanceof Error ? error . message : String ( error ) } `
5044 ) ;
5145 }
5246 }
5347
54- public static getInstance (
55- projectName : string ,
56- options : TracerOptions = { } ,
57- ) : NodeTracer {
58- const key = `NodeTracer:${ projectName } ` ;
48+ public static getInstance ( configuration : TracerConfiguration ) : NodeTracer {
49+ const key = `NodeTracer:${ configuration . projectName } ` ;
5950 if ( ! Tracer . instances . has ( key ) ) {
60- Tracer . instances . set ( key , new NodeTracer ( projectName , options ) ) ;
51+ Tracer . instances . set ( key , new NodeTracer ( configuration ) ) ;
6152 }
6253 return Tracer . instances . get ( key ) as NodeTracer ;
6354 }
6455
6556 public static createDefault ( projectName : string ) : NodeTracer {
66- return NodeTracer . getInstance ( projectName ) ;
57+ const configuration = TracerConfiguration . builder ( )
58+ . projectName ( projectName )
59+ . enableEvaluation ( true )
60+ . build ( ) ;
61+ return NodeTracer . getInstance ( configuration ) ;
6762 }
6863
6964 public static createWithConfiguration (
70- configuration : TracerConfiguration ,
65+ configuration : TracerConfiguration
7166 ) : NodeTracer {
72- return NodeTracer . getInstance ( configuration . projectName , {
73- apiKey : configuration . apiKey ,
74- organizationId : configuration . organizationId ,
75- enableEvaluation : configuration . enableEvaluation ,
76- } ) ;
67+ return new NodeTracer ( configuration ) ;
7768 }
7869
7970 public async shutdown ( ) : Promise < void > {
0 commit comments