@@ -3,17 +3,14 @@ package io.embrace.android.embracesdk.internal.otel.spans
33import io.embrace.android.embracesdk.internal.clock.millisToNanos
44import io.embrace.android.embracesdk.internal.clock.nanosToMillis
55import io.embrace.android.embracesdk.internal.clock.normalizeTimestampAsMillis
6- import io.embrace.android.embracesdk.internal.config.instrumented.InstrumentedConfigImpl
7- import io.embrace.android.embracesdk.internal.config.instrumented.schema.OtelLimitsConfig
86import io.embrace.android.embracesdk.internal.otel.attrs.EmbraceAttribute
97import io.embrace.android.embracesdk.internal.otel.attrs.asPair
10- import io.embrace.android.embracesdk.internal.otel.config.isAttributeValid
11- import io.embrace.android.embracesdk.internal.otel.config.isNameValid
128import io.embrace.android.embracesdk.internal.otel.payload.toEmbracePayload
139import io.embrace.android.embracesdk.internal.otel.schema.EmbType
1410import io.embrace.android.embracesdk.internal.otel.schema.ErrorCodeAttribute
1511import io.embrace.android.embracesdk.internal.otel.schema.ErrorCodeAttribute.Failure.fromErrorCode
1612import io.embrace.android.embracesdk.internal.otel.schema.LinkType
13+ import io.embrace.android.embracesdk.internal.otel.sdk.DataValidator
1714import io.embrace.android.embracesdk.internal.otel.sdk.fromMap
1815import io.embrace.android.embracesdk.internal.otel.sdk.hasEmbraceAttribute
1916import io.embrace.android.embracesdk.internal.otel.sdk.id.OtelIds
@@ -47,6 +44,7 @@ class EmbraceSpanFactoryImpl(
4744 private val tracer : Tracer ,
4845 private val openTelemetryClock : Clock ,
4946 private val spanRepository : SpanRepository ,
47+ private val dataValidator : DataValidator = DataValidator (),
5048 private val stopCallback : ((spanId: String ) -> Unit )? = null ,
5149 private var redactionFunction : ((key: String , value: String ) -> String )? = null ,
5250) : EmbraceSpanFactory {
@@ -77,6 +75,7 @@ class EmbraceSpanFactoryImpl(
7775 otelSpanBuilderWrapper = otelSpanBuilderWrapper,
7876 openTelemetryClock = openTelemetryClock,
7977 spanRepository = spanRepository,
78+ dataValidator = dataValidator,
8079 stopCallback = stopCallback,
8180 redactionFunction = redactionFunction,
8281 autoTerminationMode = autoTerminationMode
@@ -87,9 +86,9 @@ private class EmbraceSpanImpl(
8786 private val otelSpanBuilderWrapper : OtelSpanBuilderWrapper ,
8887 private val openTelemetryClock : Clock ,
8988 private val spanRepository : SpanRepository ,
89+ private val dataValidator : DataValidator ,
9090 private val stopCallback : ((spanId: String ) -> Unit )? = null ,
9191 private val redactionFunction : ((key: String , value: String ) -> String )? = null ,
92- private val limits : OtelLimitsConfig = InstrumentedConfigImpl .otelLimits,
9392 override val autoTerminationMode : AutoTerminationMode = AutoTerminationMode .NONE ,
9493) : EmbraceSdkSpan {
9594
@@ -213,7 +212,7 @@ private class EmbraceSpanImpl(
213212 }
214213
215214 override fun addEvent (name : String , timestampMs : Long? , attributes : Map <String , String >? ): Boolean =
216- addObject(customEvents, customEventCount, limits .getMaxCustomEventCount()) {
215+ addObject(customEvents, customEventCount, dataValidator.otelLimitsConfig .getMaxCustomEventCount()) {
217216 EmbraceSpanEvent .create(
218217 name = name,
219218 timestampMs = timestampMs?.normalizeTimestampAsMillis() ? : openTelemetryClock.now().nanosToMillis(),
@@ -222,7 +221,7 @@ private class EmbraceSpanImpl(
222221 }
223222
224223 override fun recordException (exception : Throwable , attributes : Map <String , String >? ): Boolean =
225- addObject(customEvents, customEventCount, limits .getMaxCustomEventCount()) {
224+ addObject(customEvents, customEventCount, dataValidator.otelLimitsConfig .getMaxCustomEventCount()) {
226225 val eventAttributes = mutableMapOf<String , String >()
227226 if (attributes != null ) {
228227 eventAttributes.putAll(attributes)
@@ -239,14 +238,14 @@ private class EmbraceSpanImpl(
239238 eventAttributes[ExceptionAttributes .EXCEPTION_STACKTRACE .key] = exception.truncatedStacktraceText()
240239
241240 EmbraceSpanEvent .create(
242- name = limits .getExceptionEventName(),
241+ name = dataValidator.otelLimitsConfig .getExceptionEventName(),
243242 timestampMs = openTelemetryClock.now().nanosToMillis(),
244243 attributes = eventAttributes
245244 )
246245 }
247246
248247 override fun addSystemEvent (name : String , timestampMs : Long? , attributes : Map <String , String >? ): Boolean =
249- addObject(systemEvents, systemEventCount, limits .getMaxSystemEventCount()) {
248+ addObject(systemEvents, systemEventCount, dataValidator.otelLimitsConfig .getMaxSystemEventCount()) {
250249 EmbraceSpanEvent .create(
251250 name = name,
252251 timestampMs = timestampMs?.normalizeTimestampAsMillis() ? : openTelemetryClock.now().nanosToMillis(),
@@ -281,11 +280,11 @@ private class EmbraceSpanImpl(
281280 override fun getStartTimeMs (): Long? = spanStartTimeMs
282281
283282 override fun addAttribute (key : String , value : String ): Boolean {
284- if (customAttributes.size < limits .getMaxCustomAttributeCount() &&
285- limits .isAttributeValid(key, value, otelSpanBuilderWrapper.internal)
283+ if (customAttributes.size < dataValidator.otelLimitsConfig .getMaxCustomAttributeCount() &&
284+ dataValidator .isAttributeValid(key, value, otelSpanBuilderWrapper.internal)
286285 ) {
287286 synchronized(customAttributes) {
288- if (customAttributes.size < limits .getMaxCustomAttributeCount() && isRecording) {
287+ if (customAttributes.size < dataValidator.otelLimitsConfig .getMaxCustomAttributeCount() && isRecording) {
289288 customAttributes[key] = value
290289 spanRepository.notifySpanUpdate()
291290 return true
@@ -297,7 +296,7 @@ private class EmbraceSpanImpl(
297296 }
298297
299298 override fun updateName (newName : String ): Boolean {
300- if (limits .isNameValid(newName, otelSpanBuilderWrapper.internal)) {
299+ if (dataValidator .isNameValid(newName, otelSpanBuilderWrapper.internal)) {
301300 synchronized(startedSpan) {
302301 if (! spanStarted() || isRecording) {
303302 updatedName = newName
@@ -312,12 +311,12 @@ private class EmbraceSpanImpl(
312311 }
313312
314313 override fun addSystemLink (linkedSpanContext : SpanContext , type : LinkType , attributes : Map <String , String >): Boolean =
315- addObject(systemLinks, systemLinkCount, limits .getMaxSystemLinkCount()) {
314+ addObject(systemLinks, systemLinkCount, dataValidator.otelLimitsConfig .getMaxSystemLinkCount()) {
316315 EmbraceLinkData (linkedSpanContext, mutableMapOf (type.asPair()).apply { putAll(attributes) })
317316 }
318317
319318 override fun addLink (linkedSpanContext : SpanContext , attributes : Map <String , String >? ): Boolean =
320- addObject(customLinks, customLinkCount, limits .getMaxCustomLinkCount()) {
319+ addObject(customLinks, customLinkCount, dataValidator.otelLimitsConfig .getMaxCustomLinkCount()) {
321320 EmbraceLinkData (linkedSpanContext, attributes ? : emptyMap())
322321 }
323322
@@ -415,7 +414,7 @@ private class EmbraceSpanImpl(
415414
416415 (systemEvents + redactedCustomEvents).forEach { event ->
417416 val eventAttributes = if (event.attributes.isNotEmpty()) {
418- Attributes .builder().fromMap(event.attributes, otelSpanBuilderWrapper.internal).build()
417+ Attributes .builder().fromMap(event.attributes, otelSpanBuilderWrapper.internal, dataValidator ).build()
419418 } else {
420419 Attributes .empty()
421420 }
@@ -434,7 +433,7 @@ private class EmbraceSpanImpl(
434433
435434 (systemLinks + redactedCustomLinks).forEach {
436435 val linkAttributes = if (it.attributes.isNotEmpty()) {
437- Attributes .builder().fromMap(attributes = it.attributes, false ).build()
436+ Attributes .builder().fromMap(attributes = it.attributes, false , dataValidator ).build()
438437 } else {
439438 Attributes .empty()
440439 }
0 commit comments