Skip to content
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

Add simplified emitEvent API for custom event logging in OpenTelemetryRum #650

Closed
wants to merge 3 commits into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@
import io.opentelemetry.sdk.logs.SdkLoggerProvider;
import io.opentelemetry.sdk.metrics.SdkMeterProvider;
import io.opentelemetry.sdk.trace.SdkTracerProvider;
import java.util.Map;

/**
* Entrypoint for the OpenTelemetry Real User Monitoring library for Android.
Expand Down Expand Up @@ -88,4 +89,13 @@ static OpenTelemetryRum noop() {
* recommended that you do not cache this value, but always retrieve it from here when needed.
*/
String getRumSessionId();

/**
* Emits a custom event.
*
* @param eventName The name of the event.
* @param body The body content of the event (optional).
* @param attributes Additional attributes for the event (optional).
*/
void emitEvent(String eventName, String body, Map<String, String> attributes);
}
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@
import io.opentelemetry.android.session.SessionManager;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.sdk.OpenTelemetrySdk;
import io.opentelemetry.sdk.logs.SdkEventLoggerProvider;
import java.util.Map;

final class OpenTelemetryRumImpl implements OpenTelemetryRum {

Expand All @@ -28,4 +30,22 @@ public OpenTelemetry getOpenTelemetry() {
public String getRumSessionId() {
return sessionManager.getSessionId();
}

/**
* Emits a custom event with the provided event name, body, and attributes.
*
* @param eventName The name of the event to emit.
* @param body The body content of the event (optional).
* @param attributes Additional attributes for the event (optional).
*/
@Override
public void emitEvent(String eventName, String body, Map<String, String> attributes) {
// Use the OpenTelemetry SDK to emit the event
SdkEventLoggerProvider.create(getOpenTelemetry().logsBridge())
.get("default-scope") // A scope can be dynamically assigned if needed
.builder(eventName)
.put("body", body)
.putAll(attributes)
.emit();
}
}
Loading
Loading