-
Notifications
You must be signed in to change notification settings - Fork 73
Begin altering initialize to use a type-safe DSL #1292
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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 hidden or 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
12 changes: 12 additions & 0 deletions
12
android-agent/src/main/kotlin/io/opentelemetry/android/agent/dsl/EndpointConfiguration.kt
This file contains hidden or 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,12 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.agent.dsl | ||
|
||
@OpenTelemetryDslMarker | ||
class EndpointConfiguration internal constructor( | ||
var url: String, | ||
var headers: Map<String, String> = emptyMap(), | ||
) |
57 changes: 57 additions & 0 deletions
57
android-agent/src/main/kotlin/io/opentelemetry/android/agent/dsl/HttpExportConfiguration.kt
This file contains hidden or 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,57 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.agent.dsl | ||
|
||
import io.opentelemetry.android.agent.connectivity.HttpEndpointConnectivity | ||
|
||
@OpenTelemetryDslMarker | ||
class HttpExportConfiguration internal constructor() { | ||
/** | ||
* Global URL for HTTP export requests. | ||
*/ | ||
var baseUrl: String = "" | ||
|
||
/** | ||
* Global headers that should be attached to any HTTP export requests. | ||
*/ | ||
var baseHeaders: Map<String, String> = emptyMap() | ||
|
||
internal val spansConfig: EndpointConfiguration = | ||
HttpEndpointConnectivity | ||
.forTraces( | ||
baseUrl, | ||
baseHeaders, | ||
).let(::toEndpointConfiguration) | ||
|
||
internal val logsConfig: EndpointConfiguration = | ||
HttpEndpointConnectivity | ||
.forLogs( | ||
baseUrl, | ||
baseHeaders, | ||
).let(::toEndpointConfiguration) | ||
|
||
internal val metricsConfig: EndpointConfiguration = | ||
HttpEndpointConnectivity | ||
.forMetrics( | ||
baseUrl, | ||
baseHeaders, | ||
).let(::toEndpointConfiguration) | ||
|
||
fun spans(action: EndpointConfiguration.() -> Unit) { | ||
spansConfig.action() | ||
} | ||
|
||
fun logs(action: EndpointConfiguration.() -> Unit) { | ||
logsConfig.action() | ||
} | ||
|
||
fun metrics(action: EndpointConfiguration.() -> Unit) { | ||
metricsConfig.action() | ||
} | ||
|
||
private fun toEndpointConfiguration(connectivity: HttpEndpointConnectivity): EndpointConfiguration = | ||
EndpointConfiguration(connectivity.getUrl(), connectivity.getHeaders()) | ||
} |
50 changes: 50 additions & 0 deletions
50
...id-agent/src/main/kotlin/io/opentelemetry/android/agent/dsl/OpenTelemetryConfiguration.kt
This file contains hidden or 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,50 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.agent.dsl | ||
|
||
import io.opentelemetry.android.Incubating | ||
import io.opentelemetry.android.agent.dsl.instrumentation.InstrumentationConfiguration | ||
import io.opentelemetry.android.config.OtelRumConfig | ||
|
||
/** | ||
* Type-safe config DSL that controls how OpenTelemetry should behave. | ||
*/ | ||
@OptIn(Incubating::class) | ||
@OpenTelemetryDslMarker | ||
class OpenTelemetryConfiguration internal constructor( | ||
internal val rumConfig: OtelRumConfig = OtelRumConfig(), | ||
) { | ||
internal val exportConfig: HttpExportConfiguration = HttpExportConfiguration() | ||
|
||
internal val sessionConfig: SessionConfiguration = SessionConfiguration() | ||
|
||
/** | ||
* Configures individual instrumentations. | ||
*/ | ||
internal val instrumentations: InstrumentationConfiguration = | ||
InstrumentationConfiguration(rumConfig) | ||
|
||
/** | ||
* Configures how OpenTelemetry should export telemetry over HTTP. | ||
*/ | ||
fun httpExport(action: HttpExportConfiguration.() -> Unit) { | ||
exportConfig.action() | ||
} | ||
|
||
/** | ||
* Configures individual instrumentations. | ||
*/ | ||
fun instrumentations(action: InstrumentationConfiguration.() -> Unit) { | ||
instrumentations.action() | ||
} | ||
|
||
/** | ||
* Configures session behavior. | ||
*/ | ||
fun session(action: SessionConfiguration.() -> Unit) { | ||
sessionConfig.action() | ||
} | ||
} |
16 changes: 16 additions & 0 deletions
16
android-agent/src/main/kotlin/io/opentelemetry/android/agent/dsl/SessionConfiguration.kt
This file contains hidden or 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,16 @@ | ||
/* | ||
* Copyright The OpenTelemetry Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.opentelemetry.android.agent.dsl | ||
|
||
import kotlin.time.Duration | ||
import kotlin.time.Duration.Companion.hours | ||
import kotlin.time.Duration.Companion.minutes | ||
|
||
@OpenTelemetryDslMarker | ||
class SessionConfiguration internal constructor( | ||
var backgroundInactivityTimeout: Duration = 15.minutes, | ||
var maxLifetime: Duration = 4.hours, | ||
) |
This file contains hidden or 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 hidden or 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
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe a discussion for another PR, though I'm curious about the decision process to decide which parameters are left on the initializer method's arguments, vs which ones are placed into the
Configuration
dsl?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@LikeTheSalad I'd like to move basically every parameter apart from
Application
onto theConfiguration
DSL. I wanted to keep the PR size small particularly as other folks had PRs in flight, and should be able to open another PR towards the end of the week that moves the rest.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sounds good to me, thanks for the clarification.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I've moved the rest over in #1313