-
Couldn't load subscription status.
- Fork 2
feat(android): Add conditional exporters for logs and traces #254
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
4 commits
Select commit
Hold shift + click to select a range
ea885e6
feat(android): Add conditional exporters for logs and traces
agrognetti ff31c2a
Merge branch 'main' into agrognetti/O11Y-398
agrognetti 941d432
Tests added for Conditional exporters
agrognetti 137ae73
Replace custom Composite Exporters with OTel implementations
agrognetti 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
43 changes: 43 additions & 0 deletions
43
...lib/src/main/kotlin/com/launchdarkly/observability/client/ConditionalLogRecordExporter.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,43 @@ | ||
| package com.launchdarkly.observability.client | ||
|
|
||
| import io.opentelemetry.sdk.common.CompletableResultCode | ||
| import io.opentelemetry.sdk.logs.data.LogRecordData | ||
| import io.opentelemetry.sdk.logs.export.LogRecordExporter | ||
|
|
||
| /** | ||
| * A log record exporter that conditionally forwards logs based on their source. | ||
| * This allows different filtering rules for crashes vs normal logs. | ||
| * | ||
| * @property delegate The underlying exporter to forward logs to | ||
| * @property allowNormalLogs Whether to allow normal application logs | ||
| * @property allowCrashes Whether to allow crash logs from OpenTelemetry's CrashReporter | ||
| */ | ||
| class ConditionalLogRecordExporter( | ||
| private val delegate: LogRecordExporter, | ||
| private val allowNormalLogs: Boolean, | ||
| private val allowCrashes: Boolean | ||
| ) : LogRecordExporter { | ||
|
|
||
| override fun export(logs: Collection<LogRecordData>): CompletableResultCode { | ||
| val filteredLogs = logs.filter { logRecord -> | ||
| // Check if this is a crash log (from OpenTelemetry's CrashReporter) | ||
| val instrumentationScopeName = logRecord.instrumentationScopeInfo.name | ||
| val isCrashLog = instrumentationScopeName == "io.opentelemetry.crash" | ||
|
|
||
| when { | ||
| isCrashLog -> allowCrashes | ||
| else -> allowNormalLogs | ||
| } | ||
| } | ||
|
|
||
| return if (filteredLogs.isNotEmpty()) { | ||
| delegate.export(filteredLogs) | ||
| } else { | ||
| CompletableResultCode.ofSuccess() | ||
| } | ||
| } | ||
|
|
||
| override fun flush(): CompletableResultCode = delegate.flush() | ||
|
|
||
| override fun shutdown(): CompletableResultCode = delegate.shutdown() | ||
| } |
43 changes: 43 additions & 0 deletions
43
...roid/lib/src/main/kotlin/com/launchdarkly/observability/client/ConditionalSpanExporter.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,43 @@ | ||
| package com.launchdarkly.observability.client | ||
|
|
||
| import io.opentelemetry.sdk.common.CompletableResultCode | ||
| import io.opentelemetry.sdk.trace.data.SpanData | ||
| import io.opentelemetry.sdk.trace.export.SpanExporter | ||
|
|
||
| /** | ||
| * A span exporter that conditionally forwards spans based on their source. | ||
| * This allows different filtering rules for error spans vs normal spans. | ||
| * | ||
| * @property delegate The underlying exporter to forward spans to | ||
| * @property allowNormalSpans Whether to allow normal application spans | ||
| * @property allowErrorSpans Whether to allow error spans created by recordError method | ||
| */ | ||
| class ConditionalSpanExporter( | ||
| private val delegate: SpanExporter, | ||
| private val allowNormalSpans: Boolean, | ||
| private val allowErrorSpans: Boolean | ||
| ) : SpanExporter { | ||
|
|
||
| override fun export(spans: Collection<SpanData>): CompletableResultCode { | ||
| val filteredSpans = spans.filter { spanData -> | ||
| // Check if this is an error span created by recordError method | ||
| val spanName = spanData.name | ||
| val isErrorSpan = spanName == InstrumentationManager.ERROR_SPAN_NAME | ||
|
|
||
| when { | ||
| isErrorSpan -> allowErrorSpans | ||
| else -> allowNormalSpans | ||
| } | ||
| } | ||
|
|
||
| return if (filteredSpans.isNotEmpty()) { | ||
| delegate.export(filteredSpans) | ||
| } else { | ||
| CompletableResultCode.ofSuccess() | ||
| } | ||
| } | ||
|
|
||
| override fun flush(): CompletableResultCode = delegate.flush() | ||
|
|
||
| override fun shutdown(): CompletableResultCode = delegate.shutdown() | ||
| } |
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.