Skip to content

Commit

Permalink
Rename to use Span instead of Spans in the names of things (#426)
Browse files Browse the repository at this point in the history
## Goal

Big rename to change Spans* to Span*
  • Loading branch information
bidetofevil authored Feb 16, 2024
1 parent 86985ba commit 934a05b
Show file tree
Hide file tree
Showing 39 changed files with 312 additions and 312 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -106,7 +106,7 @@ internal class TracingApiTest {
assertEquals(2, harness.fakeDeliveryModule.deliveryService.lastSentSessions.size)
val allSpans = getSdkInitSpanFromBackgroundActivity() +
checkNotNull(sessionMessage?.spans) +
checkNotNull(harness.openTelemetryModule.spansSink.completedSpans())
checkNotNull(harness.openTelemetryModule.spanSink.completedSpans())

val spansMap = allSpans.associateBy { it.name }
val sessionSpan = checkNotNull(spansMap["emb-session-span"])
Expand Down
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
package io.embrace.android.embracesdk.capture.startup

import io.embrace.android.embracesdk.internal.clock.millisToNanos
import io.embrace.android.embracesdk.internal.spans.SpansService
import io.embrace.android.embracesdk.internal.spans.SpanService

internal class StartupServiceImpl(
private val spansService: SpansService
private val spanService: SpanService
) : StartupService {

/**
Expand All @@ -15,7 +15,7 @@ internal class StartupServiceImpl(

override fun setSdkStartupInfo(startTimeMs: Long, endTimeMs: Long) {
if (sdkStartupDuration == null) {
spansService.recordCompletedSpan(
spanService.recordCompletedSpan(
name = "sdk-init",
startTimeNanos = startTimeMs.millisToNanos(),
endTimeNanos = endTimeMs.millisToNanos()
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ import io.embrace.android.embracesdk.internal.EventDescription
import io.embrace.android.embracesdk.internal.StartupEventInfo
import io.embrace.android.embracesdk.internal.clock.Clock
import io.embrace.android.embracesdk.internal.clock.millisToNanos
import io.embrace.android.embracesdk.internal.spans.SpansService
import io.embrace.android.embracesdk.internal.spans.SpanService
import io.embrace.android.embracesdk.internal.spans.toEmbraceSpanName
import io.embrace.android.embracesdk.internal.utils.Uuid.getEmbUuid
import io.embrace.android.embracesdk.logging.InternalEmbraceLogger
Expand Down Expand Up @@ -48,7 +48,7 @@ internal class EmbraceEventService(
private val logger: InternalEmbraceLogger,
workerThreadModule: WorkerThreadModule,
private val clock: Clock,
private val spansService: SpansService
private val spanService: SpanService
) : EventService, ActivityLifecycleListener, ProcessStateListener, MemoryCleanerListener {
private val backgroundWorker: BackgroundWorker

Expand Down Expand Up @@ -288,7 +288,7 @@ internal class EmbraceEventService(
private fun logStartupSpan() {
val startupEndTimeMillis = clock.now()
backgroundWorker.submit {
spansService.recordCompletedSpan(
spanService.recordCompletedSpan(
name = STARTUP_SPAN_NAME,
startTimeNanos = startupStartTime.millisToNanos(),
endTimeNanos = startupEndTimeMillis.millisToNanos(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -153,6 +153,6 @@ internal class DataCaptureServiceModuleImpl @JvmOverloads constructor(
}

override val startupService: StartupService by singleton {
StartupServiceImpl(openTelemetryModule.spansService)
StartupServiceImpl(openTelemetryModule.spanService)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -86,7 +86,7 @@ internal class DataContainerModuleImpl(
coreModule.logger,
workerThreadModule,
initModule.clock,
openTelemetryModule.spansService
openTelemetryModule.spanService
)
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -136,13 +136,13 @@ internal class ModuleInitBootstrapper(

val initTask = workerThreadModule.backgroundWorker(WorkerName.BACKGROUND_REGISTRATION).submit(TaskPriority.CRITICAL) {
Systrace.trace("spans-service-init") {
openTelemetryModule.spansService.initializeService(sdkStartTimeNanos)
openTelemetryModule.spanService.initializeService(sdkStartTimeNanos)
}
}

val serviceRegistry = coreModule.serviceRegistry
serviceRegistry.registerService(initModule.telemetryService)
serviceRegistry.registerService(openTelemetryModule.spansService)
serviceRegistry.registerService(openTelemetryModule.spanService)

systemServiceModule = Systrace.traceSynchronous("system-service-init") {
systemServiceModuleSupplier(coreModule, versionChecker)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,13 +2,13 @@ package io.embrace.android.embracesdk.injection

import io.embrace.android.embracesdk.internal.spans.CurrentSessionSpan
import io.embrace.android.embracesdk.internal.spans.CurrentSessionSpanImpl
import io.embrace.android.embracesdk.internal.spans.EmbraceSpansService
import io.embrace.android.embracesdk.internal.spans.EmbraceSpanService
import io.embrace.android.embracesdk.internal.spans.EmbraceTracer
import io.embrace.android.embracesdk.internal.spans.InternalTracer
import io.embrace.android.embracesdk.internal.spans.SpansRepository
import io.embrace.android.embracesdk.internal.spans.SpansService
import io.embrace.android.embracesdk.internal.spans.SpansSink
import io.embrace.android.embracesdk.internal.spans.SpansSinkImpl
import io.embrace.android.embracesdk.internal.spans.SpanRepository
import io.embrace.android.embracesdk.internal.spans.SpanService
import io.embrace.android.embracesdk.internal.spans.SpanSink
import io.embrace.android.embracesdk.internal.spans.SpanSinkImpl
import io.embrace.android.embracesdk.opentelemetry.OpenTelemetryConfiguration
import io.embrace.android.embracesdk.opentelemetry.OpenTelemetrySdk
import io.opentelemetry.api.trace.Tracer
Expand All @@ -26,12 +26,12 @@ internal interface OpenTelemetryModule {
/**
* Caches [EmbraceSpan] instances that are in progress or completed in the current session
*/
val spansRepository: SpansRepository
val spanRepository: SpanRepository

/**
* Provides storage for completed spans that have not been sent off-device
*/
val spansSink: SpansSink
val spanSink: SpanSink

/**
* An instance of the OpenTelemetry component obtained from the wrapped SDK to create spans
Expand All @@ -46,7 +46,7 @@ internal interface OpenTelemetryModule {
/**
* Service to record spans
*/
val spansService: SpansService
val spanService: SpanService

/**
* Implementation of public tracing API
Expand All @@ -63,17 +63,17 @@ internal class OpenTelemetryModuleImpl(
private val initModule: InitModule
) : OpenTelemetryModule {

override val spansRepository: SpansRepository by lazy {
SpansRepository()
override val spanRepository: SpanRepository by lazy {
SpanRepository()
}

override val spansSink: SpansSink by lazy {
SpansSinkImpl()
override val spanSink: SpanSink by lazy {
SpanSinkImpl()
}

override val openTelemetryConfiguration: OpenTelemetryConfiguration by lazy {
OpenTelemetryConfiguration(
spansSink
spanSink
)
}

Expand All @@ -92,15 +92,15 @@ internal class OpenTelemetryModuleImpl(
CurrentSessionSpanImpl(
clock = initModule.openTelemetryClock,
telemetryService = initModule.telemetryService,
spansRepository = spansRepository,
spansSink = spansSink,
spanRepository = spanRepository,
spanSink = spanSink,
tracerSupplier = { tracer }
)
}

override val spansService: SpansService by singleton {
EmbraceSpansService(
spansRepository = spansRepository,
override val spanService: SpanService by singleton {
EmbraceSpanService(
spanRepository = spanRepository,
currentSessionSpan = currentSessionSpan,
tracerSupplier = { tracer },
)
Expand All @@ -109,13 +109,13 @@ internal class OpenTelemetryModuleImpl(
override val embraceTracer: EmbraceTracer by singleton {
EmbraceTracer(
clock = initModule.clock,
spansService = spansService
spanService = spanService
)
}

override val internalTracer: InternalTracer by lazy {
InternalTracer(
spansRepository = spansRepository,
spanRepository = spanRepository,
embraceTracer = embraceTracer
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ internal class SessionModuleImpl(
dataCaptureServiceModule.breadcrumbService,
essentialServiceModule.userService,
androidServicesModule.preferencesService,
openTelemetryModule.spansSink,
openTelemetryModule.spanSink,
openTelemetryModule.currentSessionSpan,
sessionPropertiesService,
dataCaptureServiceModule.startupService
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@ import java.util.concurrent.atomic.AtomicReference
internal class CurrentSessionSpanImpl(
private val clock: Clock,
private val telemetryService: TelemetryService,
private val spansRepository: SpansRepository,
private val spansSink: SpansSink,
private val spanRepository: SpanRepository,
private val spanSink: SpanSink,
private val tracerSupplier: Provider<Tracer>,
) : CurrentSessionSpan, SessionSpanWriter {

Expand Down Expand Up @@ -53,12 +53,12 @@ internal class CurrentSessionSpanImpl(
// If a span can be created, always let internal spans be to be created
return if (internal) {
return true
} else if (traceCount.get() >= SpansServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION) {
} else if (traceCount.get() >= SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION) {
// If we have already reached the maximum number of spans created for this session, don't allow another one
false
} else {
synchronized(traceCount) {
traceCount.getAndIncrement() < SpansServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION
traceCount.getAndIncrement() < SpanServiceImpl.MAX_NON_INTERNAL_SPANS_PER_SESSION
}
}
}
Expand All @@ -76,7 +76,7 @@ internal class CurrentSessionSpanImpl(

if (appTerminationCause == null) {
endingSessionSpan.stop()
spansRepository.clearCompletedSpans()
spanRepository.clearCompletedSpans()
sessionSpan.set(startSessionSpan(clock.now()))
} else {
endingSessionSpan.addAttribute(
Expand All @@ -85,7 +85,7 @@ internal class CurrentSessionSpanImpl(
)
endingSessionSpan.stop()
}
return spansSink.flushSpans()
return spanSink.flushSpans()
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,15 +7,15 @@ import io.opentelemetry.sdk.trace.data.SpanData
import io.opentelemetry.sdk.trace.export.SpanExporter

/**
* Exports the given completed [Span] to the given [SpansService]
* Exports the given completed [Span] to the given [SpanService]
*
* Note: no explicit tests exist for this as its functionality is tested via the tests for [SpansServiceImpl]
* Note: no explicit tests exist for this as its functionality is tested via the tests for [SpanServiceImpl]
*/
@InternalApi
internal class EmbraceSpanExporter(private val spansSink: SpansSink) : SpanExporter {
internal class EmbraceSpanExporter(private val spanSink: SpanSink) : SpanExporter {
@Synchronized
override fun export(spans: MutableCollection<SpanData>): CompletableResultCode =
spansSink.storeCompletedSpans(spans.toList())
spanSink.storeCompletedSpans(spans.toList())

override fun flush(): CompletableResultCode = CompletableResultCode.ofSuccess()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ import java.util.concurrent.atomic.AtomicReference
internal class EmbraceSpanImpl(
private val spanBuilder: SpanBuilder,
override val parent: EmbraceSpan? = null,
private val spansRepository: SpansRepository? = null,
private val spanRepository: SpanRepository? = null,
sessionSpan: Boolean = false
) : EmbraceSpan {

Expand Down Expand Up @@ -47,7 +47,7 @@ internal class EmbraceSpanImpl(
successful = startedSpan.get() != null
}
if (successful) {
spansRepository?.trackStartedSpan(this)
spanRepository?.trackStartedSpan(this)
}
return successful
}
Expand All @@ -65,7 +65,7 @@ internal class EmbraceSpanImpl(
successful = startedSpan.get()?.isRecording == false
}
if (successful) {
spanId?.let { spansRepository?.trackedSpanStopped(it) }
spanId?.let { spanRepository?.trackedSpanStopped(it) }
}
return successful
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,26 +7,26 @@ import io.embrace.android.embracesdk.spans.ErrorCode
import io.opentelemetry.api.trace.Tracer

/**
* A [SpansService] that can be instantiated quickly. At that time, it will defer calls an implementation that handles the case when
* the SDK has not been started ([UninitializedSdkSpansService]. When [initializeService] is called during SDK startup, it will
* instantiate and initialize [SpansServiceImpl] to provide the span recording functionality.
* A [SpanService] that can be instantiated quickly. At that time, it will defer calls an implementation that handles the case when
* the SDK has not been started ([UninitializedSdkSpanService]. When [initializeService] is called during SDK startup, it will
* instantiate and initialize [SpanServiceImpl] to provide the span recording functionality.
*/
internal class EmbraceSpansService(
private val spansRepository: SpansRepository,
internal class EmbraceSpanService(
private val spanRepository: SpanRepository,
private val currentSessionSpan: CurrentSessionSpan,
private val tracerSupplier: Provider<Tracer>,
) : SpansService {
private val uninitializedSdkSpansService: UninitializedSdkSpansService = UninitializedSdkSpansService()
) : SpanService {
private val uninitializedSdkSpansService: UninitializedSdkSpanService = UninitializedSdkSpanService()

@Volatile
private var currentDelegate: SpansService = uninitializedSdkSpansService
private var currentDelegate: SpanService = uninitializedSdkSpansService

override fun initializeService(sdkInitStartTimeNanos: Long) {
if (!initialized()) {
synchronized(currentDelegate) {
if (!initialized()) {
val realSpansService = SpansServiceImpl(
spansRepository = spansRepository,
val realSpansService = SpanServiceImpl(
spanRepository = spanRepository,
currentSessionSpan = currentSessionSpan,
tracer = tracerSupplier(),
)
Expand All @@ -40,7 +40,7 @@ internal class EmbraceSpansService(
}
}

override fun initialized(): Boolean = currentDelegate is SpansServiceImpl
override fun initialized(): Boolean = currentDelegate is SpanServiceImpl

override fun createSpan(name: String, parent: EmbraceSpan?, type: EmbraceAttributes.Type, internal: Boolean): EmbraceSpan? =
currentDelegate.createSpan(name = name, parent = parent, type = type, internal = internal)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,13 +8,13 @@ import io.embrace.android.embracesdk.spans.TracingApi

internal class EmbraceTracer(
private val clock: Clock,
private val spansService: SpansService,
private val spanService: SpanService,
) : TracingApi {
override fun createSpan(name: String): EmbraceSpan? =
createSpan(name = name, parent = null)

override fun createSpan(name: String, parent: EmbraceSpan?): EmbraceSpan? =
spansService.createSpan(
spanService.createSpan(
name = name,
parent = parent,
internal = false
Expand Down Expand Up @@ -44,7 +44,7 @@ internal class EmbraceTracer(
attributes: Map<String, String>?,
events: List<EmbraceSpanEvent>?,
code: () -> T
): T = spansService.recordSpan(
): T = spanService.recordSpan(
name = name,
parent = parent,
attributes = attributes ?: emptyMap(),
Expand Down Expand Up @@ -127,7 +127,7 @@ internal class EmbraceTracer(
attributes: Map<String, String>?,
events: List<EmbraceSpanEvent>?
): Boolean =
spansService.recordCompletedSpan(
spanService.recordCompletedSpan(
name = name,
startTimeNanos = startTimeNanos,
endTimeNanos = endTimeNanos,
Expand All @@ -138,7 +138,7 @@ internal class EmbraceTracer(
errorCode = errorCode
)

override fun getSpan(spanId: String): EmbraceSpan? = spansService.getSpan(spanId = spanId)
override fun getSpan(spanId: String): EmbraceSpan? = spanService.getSpan(spanId = spanId)

/**
* Return the current time in nanoseconds for the clock instance used by the Embrace SDK. This should be used to obtain the time
Expand All @@ -147,5 +147,5 @@ internal class EmbraceTracer(
fun getSdkCurrentTimeNanos(): Long = clock.nowInNanos()

@Deprecated("Not required. Use Embrace.isStarted() to know when the full tracing API is available")
override fun isTracingAvailable(): Boolean = spansService.initialized()
override fun isTracingAvailable(): Boolean = spanService.initialized()
}
Loading

0 comments on commit 934a05b

Please sign in to comment.