MCPcopy Create free account
hub / github.com/Effect-TS/effect / addSpanAttributes

Function addSpanAttributes

packages/effect/src/unstable/ai/Telemetry.ts:337–362  ·  view source on GitHub ↗
(
  /**
   * The prefix to add to all attribute keys.
   */
  keyPrefix: string,
  /**
   * Function to transform attribute keys (e.g., camelCase to snake_case).
   */
  transformKey: (key: string) => string
)

Source from the content-addressed store, hash-verified

335 * @since 4.0.0
336 */
337export const addSpanAttributes = (
338 /**
339 * The prefix to add to all attribute keys.
340 */
341 keyPrefix: string,
342 /**
343 * Function to transform attribute keys (e.g., camelCase to snake_case).
344 */
345 transformKey: (key: string) => string
346) =>
347<Attributes extends Record<string, any>>(
348 /**
349 * The OpenTelemetry span to add attributes to.
350 */
351 span: Span,
352 /**
353 * The attributes to add to the span.
354 */
355 attributes: Attributes
356): void => {
357 for (const [key, value] of Object.entries(attributes)) {
358 if (Predicate.isNotNullish(value)) {
359 span.attribute(`${keyPrefix}.${transformKey(key)}`, value)
360 }
361 }
362}
363
364const addSpanBaseAttributes = addSpanAttributes("gen_ai", String.camelToSnake)<BaseAttributes>
365const addSpanOperationAttributes = addSpanAttributes("gen_ai.operation", String.camelToSnake)<OperationAttributes>

Callers 1

Telemetry.tsFile · 0.85

Calls 1

attributeMethod · 0.65

Tested by

no test coverage detected