From ee96ab76d6eda9f180a82278faaa36ee86201669 Mon Sep 17 00:00:00 2001 From: Marais Rossouw Date: Thu, 29 Jun 2023 22:08:44 +1000 Subject: [PATCH] chore: correct sampler and new `Resource` type --- src/_internal/index.ts | 4 ++-- src/index.d.ts | 22 +++++++++++++++------- 2 files changed, 17 insertions(+), 9 deletions(-) diff --git a/src/_internal/index.ts b/src/_internal/index.ts index 98a5b45..fc31126 100644 --- a/src/_internal/index.ts +++ b/src/_internal/index.ts @@ -1,11 +1,11 @@ // 🚨 WARNING THIS FILE WILL DUPLICATE ITSELF WITH EACH ENTRYPOINT -import type { Context, Exporter, ScopedSpans, Span } from 'rian'; +import type { Resource, Context, Exporter, ScopedSpans, Span } from 'rian'; import { is_sampled, type Traceparent } from 'tctx'; // --- -let resource: Context = {}; +let resource = {} as Resource; export function configure(name: string, attributes: Context = {}) { resource = { diff --git a/src/index.d.ts b/src/index.d.ts index 29de544..e90fd89 100644 --- a/src/index.d.ts +++ b/src/index.d.ts @@ -5,10 +5,18 @@ import type { Traceparent } from 'tctx'; /** * The exporter is called when the {@link report} method is called. */ -export type Exporter = (trace: { - resource: Context; +export type Exporter = (trace: Trace) => any; + +type Resource = { + 'service.name': string; + 'telemetry.sdk.name': string; + 'telemetry.sdk.version': string; +} & Context; + +export type Trace = { + resource: Resource; scopeSpans: IterableIterator; -}) => any; +}; export type ScopedSpans = { readonly scope: { readonly name: string }; @@ -43,15 +51,15 @@ export type Sampler = ( /** * The name of the span. */ - readonly name: string, + name: string, /** * The traceparent id of the span. */ - readonly id: Traceparent, + id: Traceparent, /** * The tracer this span belongs to. */ - readonly tracer: { readonly name: string }, + tracer: { readonly name: string }, ) => boolean; // --- spans @@ -229,7 +237,7 @@ export async function report( * configure('my-service', { 'deployment.environment': 'production', 'k8s.namespace.name': 'default' }); * ``` */ -export function configure(name: string, attributes: Context = {}): void; +export function configure(name: string, attributes: Context): void; /** * Provinding a clock allows you to control the time of the span.