-
Notifications
You must be signed in to change notification settings - Fork 42
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
* build first set of initialization events * Rename .java to .kt * swizzle to kotlin * add tests for init events * move init lower so that the specific exporter type can be evented * Update instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.kt Co-authored-by: Manoel Aranda Neto <[email protected]> * Update instrumentation/startup/src/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.kt Co-authored-by: Manoel Aranda Neto <[email protected]> * leverage defaults and simplify * clean up events class --------- Co-authored-by: Manoel Aranda Neto <[email protected]>
- Loading branch information
1 parent
8119edd
commit e40aa81
Showing
9 changed files
with
313 additions
and
110 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
55 changes: 0 additions & 55 deletions
55
.../src/main/java/io/opentelemetry/android/instrumentation/startup/InitializationEvents.java
This file was deleted.
Oops, something went wrong.
48 changes: 48 additions & 0 deletions
48
...up/src/main/java/io/opentelemetry/android/instrumentation/startup/InitializationEvents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.instrumentation.startup | ||
|
||
import io.opentelemetry.sdk.trace.export.SpanExporter | ||
|
||
interface InitializationEvents { | ||
fun sdkInitializationStarted() | ||
|
||
fun recordConfiguration(config: Map<String, String>) | ||
|
||
fun currentNetworkProviderInitialized() | ||
|
||
fun networkMonitorInitialized() | ||
|
||
fun anrMonitorInitialized() | ||
|
||
fun slowRenderingDetectorInitialized() | ||
|
||
fun crashReportingInitialized() | ||
|
||
fun spanExporterInitialized(spanExporter: SpanExporter) | ||
|
||
companion object { | ||
@JvmField | ||
val NO_OP: InitializationEvents = | ||
object : InitializationEvents { | ||
override fun sdkInitializationStarted() {} | ||
|
||
override fun recordConfiguration(config: Map<String, String>) {} | ||
|
||
override fun currentNetworkProviderInitialized() {} | ||
|
||
override fun networkMonitorInitialized() {} | ||
|
||
override fun anrMonitorInitialized() {} | ||
|
||
override fun slowRenderingDetectorInitialized() {} | ||
|
||
override fun crashReportingInitialized() {} | ||
|
||
override fun spanExporterInitialized(spanExporter: SpanExporter) {} | ||
} | ||
} | ||
} |
52 changes: 0 additions & 52 deletions
52
...c/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.java
This file was deleted.
Oops, something went wrong.
95 changes: 95 additions & 0 deletions
95
...src/main/java/io/opentelemetry/android/instrumentation/startup/SdkInitializationEvents.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.instrumentation.startup | ||
|
||
import io.opentelemetry.android.common.RumConstants | ||
import io.opentelemetry.api.common.AttributeKey | ||
import io.opentelemetry.api.common.Attributes | ||
import io.opentelemetry.api.incubator.logs.AnyValue | ||
import io.opentelemetry.sdk.OpenTelemetrySdk | ||
import io.opentelemetry.sdk.logs.internal.SdkEventLoggerProvider | ||
import io.opentelemetry.sdk.trace.export.SpanExporter | ||
import java.time.Instant | ||
import java.util.function.Consumer | ||
import java.util.function.Supplier | ||
|
||
class SdkInitializationEvents(private val clock: Supplier<Instant> = Supplier { Instant.now() }) : InitializationEvents { | ||
private val events = mutableListOf<Event>() | ||
|
||
override fun sdkInitializationStarted() { | ||
addEvent(RumConstants.Events.INIT_EVENT_STARTED) | ||
} | ||
|
||
override fun recordConfiguration(config: Map<String, String>) { | ||
val map = mutableMapOf<String, AnyValue<*>>() | ||
config.entries.forEach( | ||
Consumer { e: Map.Entry<String, String> -> | ||
map[e.key] = AnyValue.of(e.value) | ||
}, | ||
) | ||
val body = AnyValue.of(map) | ||
addEvent(RumConstants.Events.INIT_EVENT_CONFIG, body = body) | ||
} | ||
|
||
override fun currentNetworkProviderInitialized() { | ||
addEvent(RumConstants.Events.INIT_EVENT_NET_PROVIDER) | ||
} | ||
|
||
override fun networkMonitorInitialized() { | ||
addEvent(RumConstants.Events.INIT_EVENT_NET_MONITOR) | ||
} | ||
|
||
override fun anrMonitorInitialized() { | ||
addEvent(RumConstants.Events.INIT_EVENT_ANR_MONITOR) | ||
} | ||
|
||
override fun slowRenderingDetectorInitialized() { | ||
addEvent(RumConstants.Events.INIT_EVENT_JANK_MONITOR) | ||
} | ||
|
||
override fun crashReportingInitialized() { | ||
addEvent(RumConstants.Events.INIT_EVENT_CRASH_REPORTER) | ||
} | ||
|
||
override fun spanExporterInitialized(spanExporter: SpanExporter) { | ||
val attributes = | ||
Attributes.of(AttributeKey.stringKey("span.exporter"), spanExporter.toString()) | ||
addEvent(RumConstants.Events.INIT_EVENT_SPAN_EXPORTER, attr = attributes) | ||
} | ||
|
||
fun finish(sdk: OpenTelemetrySdk) { | ||
val loggerProvider = sdk.sdkLoggerProvider | ||
val eventLogger = | ||
SdkEventLoggerProvider.create(loggerProvider).get("otel.initialization.events") | ||
events.forEach { event: Event -> | ||
val eventBuilder = | ||
eventLogger.builder(event.name) | ||
.setTimestamp(event.timestamp) | ||
.setAttributes(event.attributes) | ||
if (event.body != null) { | ||
// TODO: Config is technically correct because config is the only startup event | ||
// with a body, but this is ultimately clunky/fragile. | ||
eventBuilder.put("config", event.body) | ||
} | ||
eventBuilder.emit() | ||
} | ||
} | ||
|
||
private fun addEvent( | ||
name: String, | ||
attr: Attributes? = null, | ||
body: AnyValue<*>? = null, | ||
) { | ||
events.add(Event(clock.get(), name, attr, body)) | ||
} | ||
|
||
private data class Event( | ||
val timestamp: Instant, | ||
val name: String, | ||
val attributes: Attributes?, | ||
val body: AnyValue<*>? = null, | ||
) | ||
} |
Oops, something went wrong.