Skip to content

Commit

Permalink
88 - Do not require workspace ID for creating spans
Browse files Browse the repository at this point in the history
  • Loading branch information
buckyroberts committed Aug 19, 2024
1 parent 10729f2 commit fb19148
Show file tree
Hide file tree
Showing 3 changed files with 5 additions and 15 deletions.
11 changes: 2 additions & 9 deletions src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -57,34 +57,27 @@ export class PromptLayer {
group: GroupManager;
track: TrackManager;
enableTracing: boolean;
workspaceId?: number;
wrapWithSpan: typeof wrapWithSpan;

constructor({
apiKey = process.env.PROMPTLAYER_API_KEY,
enableTracing = false,
workspaceId,
}: ClientOptions = {}) {
if (apiKey === undefined) {
throw new Error(
"PromptLayer API key not provided. Please set the PROMPTLAYER_API_KEY environment variable or pass the api_key parameter."
);
}

if (enableTracing && workspaceId === undefined) {
throw new Error("Please set a workspaceId to enable tracing.")
}

this.apiKey = apiKey;
this.enableTracing = enableTracing;
this.templates = new TemplateManager(apiKey);
this.group = new GroupManager(apiKey);
this.track = new TrackManager(apiKey);
this.workspaceId = workspaceId;
this.wrapWithSpan = wrapWithSpan;

if (enableTracing && workspaceId) {
setupTracing(enableTracing, workspaceId);
if (enableTracing) {
setupTracing(enableTracing);
}
}

Expand Down
5 changes: 1 addition & 4 deletions src/span-exporter.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,13 +7,11 @@ class PromptLayerSpanExporter implements SpanExporter {
private apiKey: string | undefined;
private enableTracing: boolean;
private url: string;
private workspaceId: number;

constructor(enableTracing: boolean, workspaceId: number) {
constructor(enableTracing: boolean) {
this.apiKey = process.env.PROMPTLAYER_API_KEY;
this.enableTracing = enableTracing;
this.url = `${URL_API_PROMPTLAYER}/spans-bulk`;
this.workspaceId = workspaceId;
}

private attributesToObject(attributes: Attributes | undefined): Record<string, any> {
Expand Down Expand Up @@ -92,7 +90,6 @@ class PromptLayerSpanExporter implements SpanExporter {
},
body: JSON.stringify({
spans: requestData,
workspace_id: this.workspaceId,
}),
})
.then(response => {
Expand Down
4 changes: 2 additions & 2 deletions src/tracing.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,9 +7,9 @@ export const getTracer = (name: string = 'promptlayer-tracer') => {
return opentelemetry.trace.getTracer(name);
}

export const setupTracing = (enableTracing: boolean, workspaceId: number) => {
export const setupTracing = (enableTracing: boolean) => {
const provider = new NodeTracerProvider();
const exporter = new PromptLayerSpanExporter(enableTracing, workspaceId);
const exporter = new PromptLayerSpanExporter(enableTracing);
const processor = new SimpleSpanProcessor(exporter);
provider.addSpanProcessor(processor);
provider.register();
Expand Down

0 comments on commit fb19148

Please sign in to comment.