Skip to content

Commit

Permalink
feat(BullMQOtel): rename Otel to BullMQOtel and add devDependencies
Browse files Browse the repository at this point in the history
  • Loading branch information
fgozdz committed Oct 10, 2024
1 parent 85ee824 commit 417fe82
Show file tree
Hide file tree
Showing 4 changed files with 57 additions and 65 deletions.
12 changes: 7 additions & 5 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -26,18 +26,20 @@
},
"homepage": "https://github.com/taskforcesh/bullmq-otel#readme",
"dependencies": {
"@opentelemetry/api": "^1.9.0",
"bullmq": "^5.12.12",
"typedoc": "^0.26.6",
"typescript": "^5.5.4"
},
"devDependencies": {
"@commitlint/cli": "^19.4.1",
"@commitlint/config-conventional": "^19.4.1",
"@opentelemetry/api": "^1.9.0",
"@semantic-release/changelog": "^6.0.3",
"@semantic-release/commit-analyzer": "^13.0.0",
"@semantic-release/git": "^10.0.1",
"@semantic-release/github": "^10.1.7",
"@semantic-release/npm": "^12.0.1",
"@semantic-release/release-notes-generator": "^14.0.1",
"bullmq": "^5.12.12",
"typedoc": "^0.26.6",
"typescript": "^5.5.4"
"@semantic-release/release-notes-generator": "^14.0.1"
},
"config": {
"commitizen": {
Expand Down
49 changes: 49 additions & 0 deletions src/bullMQOtel.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
import { TraceAPI, trace as OtelTrace, PropagationAPI, ContextAPI, context, propagation, Context as OtelContext, Span as OtelSpan } from '@opentelemetry/api';
import { Carrier, ContextManager, Telemetry, Trace, Tracer } from 'bullmq';

class OTelContextManager implements ContextManager<OtelContext> {
private contextAPI: ContextAPI = context;

getMetadata(ctx: OtelContext) {
const metadata: Carrier = {};
propagation.inject(ctx, metadata);
return metadata;
}

fromMetadata(activeCtx: OtelContext, metadata: Record<string, string>) {
const ctx = propagation.extract(activeCtx, metadata);
return ctx;
}

with<A extends (...args: any[]) => any>(ctx: OtelContext, fn: A): ReturnType<A> {
return this.contextAPI.with(ctx, fn);
}

active(): OtelContext {
return this.contextAPI.active();
}
}

class OTelTrace implements Trace<OtelSpan> {
getTracer(name: string, version?: string): Tracer {
return OtelTrace.getTracer(name, version);
}

setSpan(ctx: OtelContext, span: OtelSpan): OtelContext {
return OtelTrace.setSpan(ctx, span);
}
}

export class BullMQOtel implements Telemetry<OtelContext> {
trace: OTelTrace;
contextManager: OTelContextManager;
tracerName: string;
propagation: PropagationAPI;

constructor(tracerName: string) {
this.trace = new OTelTrace();
this.contextManager = new OTelContextManager();
this.tracerName = tracerName;
this.propagation = propagation;
}
};
2 changes: 1 addition & 1 deletion src/index.ts
Original file line number Diff line number Diff line change
@@ -1 +1 @@
export * from './otel';
export * from './bullMQOtel';
59 changes: 0 additions & 59 deletions src/otel.ts

This file was deleted.

0 comments on commit 417fe82

Please sign in to comment.