UNPKG

@ogcio/o11y-sdk-node

Version:

Opentelemetry standard instrumentation SDK for NodeJS based project

53 lines (41 loc) 1.69 kB
import { Context } from "@opentelemetry/api"; import { describe, expect, it } from "vitest"; import { EnrichSpanProcessor } from "../../lib/processor/enrich-span-processor.js"; import { MockSpan } from "../utils/mock-signals.js"; describe("EnrichSpanProcessor", () => { it("should set static attributes on span", () => { const spanAttributes = { key1: "value1", key2: 123, }; const processor = new EnrichSpanProcessor(spanAttributes); const mockSpan = new MockSpan(); const mockContext = {} as Context; processor.onStart(mockSpan, mockContext); expect(mockSpan.attributes["key1"]).toBe("value1"); expect(mockSpan.attributes["key2"]).toBe(123); }); it("should set dynamic attributes on span", () => { const spanAttributes = { dynamicKey: () => "dynamicValue", }; const processor = new EnrichSpanProcessor(spanAttributes); const mockSpan = new MockSpan(); const mockContext = {} as Context; processor.onStart(mockSpan, mockContext); expect(mockSpan.attributes["dynamicKey"]).toBe("dynamicValue"); }); it("should not set attributes if none are provided", () => { const processor = new EnrichSpanProcessor(); const mockSpan = new MockSpan(); const mockContext = {} as Context; processor.onStart(mockSpan, mockContext); expect(mockSpan.attributes["key1"]).toBeUndefined(); }); it("default method, should maintain default behaviour", async () => { const processor = new EnrichSpanProcessor(); expect(processor.onEnd(null!)).toBeUndefined(); expect(await processor.shutdown()).toBeUndefined(); expect(await processor.forceFlush()).toBeUndefined(); }); });