Skip to content

Commit

Permalink
js: stub out observe api datadog
Browse files Browse the repository at this point in the history
  • Loading branch information
G4Vi committed Aug 7, 2024
1 parent 890cd18 commit 6b924c6
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 2 deletions.
19 changes: 18 additions & 1 deletion js/src/lib/adapters/datadog/formatter.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,9 @@
import {
Nanoseconds,
Log,
MemoryGrowAmount,
Metric,
MetricFormat,
Nanoseconds,
newSpanId,
newTraceId,
TelemetryId,
Expand Down Expand Up @@ -52,6 +55,20 @@ export const addAllocation = (span: Span, amount: MemoryGrowAmount) => {
span.meta[allocationKey] = sumAmount.toString();
};

export const addMetric = (span: Span, metric: Metric) => {
if (metric.format !== MetricFormat.StatsdFormat) {
console.error('cannot add non-statsd metric');
return;
}
const [key, value] = metric.message.split(/:(.*)/);
};

export const addTags = (span: Span, tags: string[]) => {
};

export const addLog = (span: Span, log: Log) => {
};

export class DatadogFormatter {
constructor(public traces: Trace[]) { }

Expand Down
17 changes: 16 additions & 1 deletion js/src/lib/adapters/datadog/mod.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,13 +5,19 @@ import {
CustomEvent,
FunctionCall,
MemoryGrow,
Metric,
MetricFormat,
Log,
LogLevel,
ObserveEvent,
Options,
TelemetryId,
WASM,
SpanTags,
} from "../../mod.ts";
import { SpanCollector } from "../../collectors/span/mod.ts";
import { addAllocation, DatadogFormatter, Trace } from "./formatter.ts";
import { addAllocation, addMetric, addTags, addLog, DatadogFormatter, Trace } from "./formatter.ts";

export enum DatadogTraceType {
Web = "web",
Db = "db",
Expand Down Expand Up @@ -179,6 +185,15 @@ export class DatadogAdapter extends Adapter {
if (event instanceof MemoryGrow) {
addAllocation(span, event.amount);
}
if (event instanceof Metric) {
addMetric(span, event);
}
if (event instanceof SpanTags) {
addTags(span, event.tags);
}
if (event instanceof Log) {
addLog(span, event);
}
});
}

Expand Down

0 comments on commit 6b924c6

Please sign in to comment.