-
Notifications
You must be signed in to change notification settings - Fork 29
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
fix: separation of tracing to a different package
- Loading branch information
Showing
5 changed files
with
53 additions
and
32 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai"; | ||
import { initInstrumentations } from "./tracing"; | ||
|
||
export * from "./errors"; | ||
export { InitializeOptions } from "./interfaces"; | ||
export { initialize } from "./configuration"; | ||
|
||
export const INSTRUMENTATIONS = [new OpenAIInstrumentation()]; | ||
initInstrumentations(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
import { NodeSDK } from "@opentelemetry/sdk-node"; | ||
import { | ||
SimpleSpanProcessor, | ||
BatchSpanProcessor, | ||
} from "@opentelemetry/sdk-trace-node"; | ||
import { OTLPTraceExporter } from "@opentelemetry/exporter-trace-otlp-proto"; | ||
import { Resource } from "@opentelemetry/resources"; | ||
import { SemanticResourceAttributes } from "@opentelemetry/semantic-conventions"; | ||
import { InitializeOptions } from "../interfaces"; | ||
import { OpenAIInstrumentation } from "@traceloop/instrumentation-openai"; | ||
|
||
let _sdk: NodeSDK; | ||
let instrumentations: any[] = []; | ||
|
||
export const initInstrumentations = () => { | ||
instrumentations.push(new OpenAIInstrumentation()); | ||
}; | ||
|
||
/** | ||
* Initializes the Traceloop SDK. | ||
* Must be called once before any other SDK methods. | ||
* | ||
* @param options - The options to initialize the SDK. See the {@link InitializeOptions} for details. | ||
* @throws {InitializationError} if the configuration is invalid or if failed to fetch feature data. | ||
*/ | ||
export const startTracing = (options: InitializeOptions) => { | ||
const traceExporter = new OTLPTraceExporter({ | ||
url: `${options.baseUrl}/v1/traces`, | ||
headers: { Authorization: `Bearer ${options.apiKey}` }, | ||
}); | ||
|
||
_sdk = new NodeSDK({ | ||
resource: new Resource({ | ||
[SemanticResourceAttributes.SERVICE_NAME]: options.appName, | ||
}), | ||
spanProcessor: options.disableBatch | ||
? new SimpleSpanProcessor(traceExporter) | ||
: new BatchSpanProcessor(traceExporter), | ||
traceExporter, | ||
instrumentations, | ||
}); | ||
|
||
_sdk.start(); | ||
}; |