From 6b924c6a1897432c3d1d671e78dc9c96adf520ef Mon Sep 17 00:00:00 2001 From: Gavin Hayes Date: Wed, 7 Aug 2024 16:36:20 -0400 Subject: [PATCH] js: stub out observe api datadog --- js/src/lib/adapters/datadog/formatter.ts | 19 ++++++++++++++++++- js/src/lib/adapters/datadog/mod.ts | 17 ++++++++++++++++- 2 files changed, 34 insertions(+), 2 deletions(-) diff --git a/js/src/lib/adapters/datadog/formatter.ts b/js/src/lib/adapters/datadog/formatter.ts index 1df8683..53a5199 100644 --- a/js/src/lib/adapters/datadog/formatter.ts +++ b/js/src/lib/adapters/datadog/formatter.ts @@ -1,6 +1,9 @@ import { - Nanoseconds, + Log, MemoryGrowAmount, + Metric, + MetricFormat, + Nanoseconds, newSpanId, newTraceId, TelemetryId, @@ -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[]) { } diff --git a/js/src/lib/adapters/datadog/mod.ts b/js/src/lib/adapters/datadog/mod.ts index 5176ae9..316854d 100644 --- a/js/src/lib/adapters/datadog/mod.ts +++ b/js/src/lib/adapters/datadog/mod.ts @@ -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", @@ -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); + } }); }