@@ -22,6 +22,7 @@ import {
2222 InstrumentationLibrary ,
2323 isTimeInput ,
2424 timeInputToHrTime ,
25+ sanitizeAttributes ,
2526} from '@opentelemetry/core' ;
2627import { Resource } from '@opentelemetry/resources' ;
2728import { SemanticAttributes } from '@opentelemetry/semantic-conventions' ;
@@ -30,7 +31,7 @@ import { TimedEvent } from './TimedEvent';
3031import { Tracer } from './Tracer' ;
3132import { SpanProcessor } from './SpanProcessor' ;
3233import { SpanLimits } from './types' ;
33- import { SpanAttributeValue , Context } from '@opentelemetry/api' ;
34+ import { AttributeValue , Context } from '@opentelemetry/api' ;
3435import { ExceptionEventName } from './enums' ;
3536
3637/**
@@ -42,7 +43,7 @@ export class Span implements api.Span, ReadableSpan {
4243 private readonly _spanContext : api . SpanContext ;
4344 readonly kind : api . SpanKind ;
4445 readonly parentSpanId ?: string ;
45- readonly attributes : api . SpanAttributes = { } ;
46+ readonly attributes : api . Attributes = { } ;
4647 readonly links : api . Link [ ] = [ ] ;
4748 readonly events : TimedEvent [ ] = [ ] ;
4849 readonly startTime : api . HrTime ;
@@ -88,7 +89,7 @@ export class Span implements api.Span, ReadableSpan {
8889 return this . _spanContext ;
8990 }
9091
91- setAttribute ( key : string , value ?: SpanAttributeValue ) : this;
92+ setAttribute ( key : string , value ?: AttributeValue ) : this;
9293 setAttribute ( key : string , value : unknown ) : this {
9394 if ( value == null || this . _isSpanEnded ( ) ) return this ;
9495 if ( key . length === 0 ) {
@@ -111,7 +112,7 @@ export class Span implements api.Span, ReadableSpan {
111112 return this ;
112113 }
113114
114- setAttributes ( attributes : api . SpanAttributes ) : this {
115+ setAttributes ( attributes : api . Attributes ) : this {
115116 for ( const [ k , v ] of Object . entries ( attributes ) ) {
116117 this . setAttribute ( k , v ) ;
117118 }
@@ -127,7 +128,7 @@ export class Span implements api.Span, ReadableSpan {
127128 */
128129 addEvent (
129130 name : string ,
130- attributesOrStartTime ?: api . SpanAttributes | api . TimeInput ,
131+ attributesOrStartTime ?: api . Attributes | api . TimeInput ,
131132 startTime ?: api . TimeInput
132133 ) : this {
133134 if ( this . _isSpanEnded ( ) ) return this ;
@@ -148,9 +149,11 @@ export class Span implements api.Span, ReadableSpan {
148149 if ( typeof startTime === 'undefined' ) {
149150 startTime = hrTime ( ) ;
150151 }
152+
153+ const attributes = sanitizeAttributes ( attributesOrStartTime ) ;
151154 this . events . push ( {
152155 name,
153- attributes : attributesOrStartTime as api . SpanAttributes ,
156+ attributes,
154157 time : timeInputToHrTime ( startTime ) ,
155158 } ) ;
156159 return this ;
@@ -193,7 +196,7 @@ export class Span implements api.Span, ReadableSpan {
193196 }
194197
195198 recordException ( exception : api . Exception , time : api . TimeInput = hrTime ( ) ) : void {
196- const attributes : api . SpanAttributes = { } ;
199+ const attributes : api . Attributes = { } ;
197200 if ( typeof exception === 'string' ) {
198201 attributes [ SemanticAttributes . EXCEPTION_MESSAGE ] = exception ;
199202 } else if ( exception ) {
@@ -217,7 +220,7 @@ export class Span implements api.Span, ReadableSpan {
217220 attributes [ SemanticAttributes . EXCEPTION_TYPE ] ||
218221 attributes [ SemanticAttributes . EXCEPTION_MESSAGE ]
219222 ) {
220- this . addEvent ( ExceptionEventName , attributes as api . SpanAttributes , time ) ;
223+ this . addEvent ( ExceptionEventName , attributes , time ) ;
221224 } else {
222225 api . diag . warn ( `Failed to record an exception ${ exception } ` ) ;
223226 }
@@ -260,7 +263,7 @@ export class Span implements api.Span, ReadableSpan {
260263 * @param value Attribute value
261264 * @returns truncated attribute value if required, otherwise same value
262265 */
263- private _truncateToSize ( value : SpanAttributeValue ) : SpanAttributeValue {
266+ private _truncateToSize ( value : AttributeValue ) : AttributeValue {
264267 const limit = this . _attributeValueLengthLimit ;
265268 // Check limit
266269 if ( limit <= 0 ) {
0 commit comments