-
Notifications
You must be signed in to change notification settings - Fork 4
feat: Android LDObserve / LDReplay thread-safe API #537
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
Show all changes
15 commits
Select commit
Hold shift + click to select a range
153987d
remove protobuf
abelonogov-ld e623831
bump version
abelonogov-ld 90a69a6
LDObserve, LDReplay thread-safety
abelonogov-ld e4c2236
read1
abelonogov-ld 3188527
make it readable
abelonogov-ld 6f1be0e
change back
abelonogov-ld 08ac324
fix unit tests
abelonogov-ld a03d828
remove SDK_NAME constant from Observability class
abelonogov-ld e1cf0f6
add warning
abelonogov-ld 67153ae
fix CI compilation
abelonogov-ld 48dc023
Merge branch 'main' into andrey/maui-async-init
abelonogov-ld 624cf02
TOCTOU
abelonogov-ld db6a759
Merge branch 'andrey/maui-async-init' of github.com:launchdarkly/obse…
abelonogov-ld 8d34bae
fix failing
abelonogov-ld 1a8807b
fix initializaiton
abelonogov-ld 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
11 changes: 1 addition & 10 deletions
11
...e/LDObserve/LDObserve.xcodeproj/project.xcworkspace/xcshareddata/swiftpm/Package.resolved
Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.
Oops, something went wrong.
2 changes: 1 addition & 1 deletion
2
sdk/@launchdarkly/mobile-dotnet/observability/Directory.Build.props
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
84 changes: 84 additions & 0 deletions
84
...ndroid/lib/src/main/kotlin/com/launchdarkly/observability/client/ObservabilityResource.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,84 @@ | ||
| package com.launchdarkly.observability.client | ||
|
|
||
| import com.launchdarkly.observability.BuildConfig | ||
| import com.launchdarkly.observability.api.ObservabilityOptions | ||
| import io.opentelemetry.api.common.AttributeKey | ||
| import io.opentelemetry.api.common.Attributes | ||
| import io.opentelemetry.sdk.resources.Resource | ||
|
|
||
| /** | ||
| * Default Highlight/OTel "distro" attributes attached to every observability [Resource]. | ||
| * | ||
| * Exposed (internally) so the [com.launchdarkly.observability.plugin.Observability] LDClient | ||
| * plugin can seed its mutable `distroAttributes` field with the same defaults the standalone | ||
| * [com.launchdarkly.observability.sdk.LDObserve.init] path uses, keeping the two init paths | ||
| * in sync without duplicating string literals. | ||
| */ | ||
| internal val DEFAULT_DISTRO_ATTRIBUTES: Map<String, String> = mapOf( | ||
| "telemetry.distro.name" to "launchdarkly-observability-android", | ||
| "telemetry.distro.version" to BuildConfig.OBSERVABILITY_SDK_VERSION, | ||
| ) | ||
|
|
||
| /** | ||
| * Builds the OpenTelemetry [Resource] attached to every observability signal emitted by this SDK. | ||
| * | ||
| * Single source of truth for resource shape, used by both initialization paths: | ||
| * - [com.launchdarkly.observability.plugin.Observability.onPluginsReady] (LDClient plugin path), | ||
| * which flattens its [com.launchdarkly.sdk.android.integrations.EnvironmentMetadata] into the | ||
| * [applicationId], [applicationVersion], and [sdkVersion] params. | ||
| * - [com.launchdarkly.observability.sdk.LDObserve.init] (standalone path), which has no | ||
| * LDClient metadata and simply omits those params. | ||
| * | ||
| * Attribute precedence (later wins for duplicate keys): | ||
| * 1. OpenTelemetry default resource attributes, minus `service.name`. | ||
| * 2. `highlight.project_id` = [sdkKey]. | ||
| * 3. [distroAttributes] (defaults to [DEFAULT_DISTRO_ATTRIBUTES] — `telemetry.distro.{name,version}`). | ||
| * 4. Caller-supplied [ObservabilityOptions.resourceAttributes]. | ||
| * 5. `launchdarkly.application.id`, `launchdarkly.application.version`, `launchdarkly.sdk.version` | ||
| * when provided (LDClient plugin path only). | ||
| * | ||
| * The metadata-derived attributes (5) come *after* the user's [ObservabilityOptions.resourceAttributes] | ||
| * so user overrides cannot accidentally clobber LDClient identity. If a user genuinely wants to | ||
| * override `launchdarkly.*`, they shouldn't be using these attribute names anyway. | ||
| * | ||
| * @param sdkKey LaunchDarkly mobile key; written as `highlight.project_id`. | ||
| * @param options Observability options; [ObservabilityOptions.resourceAttributes] is appended. | ||
| * @param distroAttributes Distro identification, defaults to [DEFAULT_DISTRO_ATTRIBUTES]. | ||
| * The LDClient plugin passes its mutable `distroAttributes` field here | ||
| * so callers that customize the field still see their changes. | ||
| * @param applicationId `launchdarkly.application.id`, or `null` to omit. | ||
| * @param applicationVersion `launchdarkly.application.version`, or `null` to omit. | ||
| * @param sdkVersion `launchdarkly.sdk.version`, or `null` to omit. Already formatted | ||
| * (typically `"$sdkName/$sdkVersion"`) — this helper does not compose it. | ||
| */ | ||
| internal fun buildObservabilityResource( | ||
| sdkKey: String, | ||
| options: ObservabilityOptions, | ||
| distroAttributes: Map<String, String> = DEFAULT_DISTRO_ATTRIBUTES, | ||
| applicationId: String? = null, | ||
| applicationVersion: String? = null, | ||
| sdkVersion: String? = null, | ||
| ): Resource { | ||
| val builder = Attributes.builder() | ||
|
|
||
| Resource.getDefault().attributes.forEach { key, value -> | ||
| if (key.key != "service.name") { | ||
| @Suppress("UNCHECKED_CAST") | ||
| builder.put(key as AttributeKey<Any>, value) | ||
| } | ||
| } | ||
|
|
||
| builder.put("highlight.project_id", sdkKey) | ||
|
|
||
| distroAttributes.forEach { (key, value) -> | ||
| builder.put(AttributeKey.stringKey(key), value) | ||
| } | ||
|
|
||
| builder.putAll(options.resourceAttributes) | ||
|
|
||
| applicationId?.let { builder.put("launchdarkly.application.id", it) } | ||
| applicationVersion?.let { builder.put("launchdarkly.application.version", it) } | ||
| sdkVersion?.let { builder.put("launchdarkly.sdk.version", it) } | ||
|
|
||
| return Resource.create(builder.build()) | ||
| } |
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
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
Oops, something went wrong.
Oops, something went wrong.
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.
Uh oh!
There was an error while loading. Please reload this page.