Skip to content

Commit

Permalink
Merge branch 'main' into update_renovate
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk authored Aug 28, 2023
2 parents 3430ace + ff7915c commit 257aeb3
Show file tree
Hide file tree
Showing 6 changed files with 45 additions and 24 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,10 +22,10 @@
*/
public class SessionIdRatioBasedSampler implements Sampler {
private final Sampler ratioBasedSampler;
private final SessionId sessionid;
private final SessionId sessionId;

public SessionIdRatioBasedSampler(double ratio, SessionId sessionId) {
this.sessionid = sessionId;
this.sessionId = sessionId;
// SessionId uses the same format as TraceId, so we can reuse trace ID ratio sampler.
this.ratioBasedSampler = Sampler.traceIdRatioBased(ratio);
}
Expand All @@ -40,7 +40,7 @@ public SamplingResult shouldSample(
List<LinkData> parentLinks) {
// Replace traceId with sessionId
return ratioBasedSampler.shouldSample(
parentContext, sessionid.getSessionId(), name, spanKind, attributes, parentLinks);
parentContext, sessionId.getSessionId(), name, spanKind, attributes, parentLinks);
}

@Override
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,26 +6,21 @@
package io.opentelemetry.android.instrumentation;

import android.app.Activity;
import androidx.annotation.Nullable;
import androidx.fragment.app.Fragment;

public interface ScreenNameExtractor {

@Nullable
String extract(Activity activity);

@Nullable
String extract(Fragment fragment);

ScreenNameExtractor DEFAULT =
new ScreenNameExtractor() {
@Nullable
@Override
public String extract(Activity activity) {
return useAnnotationOrClassName(activity.getClass());
}

@Nullable
@Override
public String extract(Fragment fragment) {
return useAnnotationOrClassName(fragment.getClass());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -139,12 +139,15 @@ public static Builder builder(Activity activity) {
}

static class Builder {
private static final ActiveSpan INVALID_ACTIVE_SPAN = new ActiveSpan(() -> null);
private static final Tracer INVALID_TRACER = spanName -> null;
private static final AppStartupTimer INVALID_TIMER = new AppStartupTimer();
private final Activity activity;
public String screenName;
public String screenName = "unknown_screen";
private AtomicReference<String> initialAppActivity = new AtomicReference<>();
private Tracer tracer;
private AppStartupTimer appStartupTimer;
private ActiveSpan activeSpan;
private Tracer tracer = INVALID_TRACER;
private AppStartupTimer appStartupTimer = INVALID_TIMER;
private ActiveSpan activeSpan = INVALID_ACTIVE_SPAN;

public Builder(Activity activity) {
this.activity = activity;
Expand Down Expand Up @@ -184,13 +187,22 @@ private String getActivityName() {
return activity.getClass().getSimpleName();
}

public ActivityTracer build() {
return new ActivityTracer(this);
}

public Builder setScreenName(String screenName) {
this.screenName = screenName;
return this;
}

public ActivityTracer build() {
if (activeSpan == INVALID_ACTIVE_SPAN) {
throw new IllegalStateException("activeSpan must be configured.");
}
if (tracer == INVALID_TRACER) {
throw new IllegalStateException("tracer must be configured.");
}
if (appStartupTimer == INVALID_TIMER) {
throw new IllegalStateException("appStartupTimer must be configured.");
}
return new ActivityTracer(this);
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,12 @@ static Builder builder(Fragment fragment) {
}

static class Builder {
private static final ActiveSpan INVALID_ACTIVE_SPAN = new ActiveSpan(() -> null);
private static final Tracer INVALID_TRACER = spanName -> null;
private final Fragment fragment;
public String screenName;
private Tracer tracer;
private ActiveSpan activeSpan;
public String screenName = "";
private Tracer tracer = INVALID_TRACER;
private ActiveSpan activeSpan = INVALID_ACTIVE_SPAN;

public Builder(Fragment fragment) {
this.fragment = fragment;
Expand All @@ -99,6 +101,12 @@ public String getFragmentName() {
}

FragmentTracer build() {
if (activeSpan == INVALID_ACTIVE_SPAN) {
throw new IllegalStateException("activeSpan must be configured.");
}
if (tracer == INVALID_TRACER) {
throw new IllegalStateException("tracer must be configured.");
}
return new FragmentTracer(this);
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -12,9 +12,11 @@
import java.util.function.Function;

public class AndroidLifecycleInstrumentationBuilder {
private static final VisibleScreenTracker INVALID_SCREEN_TRACKER = new VisibleScreenTracker();
private static final AppStartupTimer INVALID_TIMER = new AppStartupTimer();
ScreenNameExtractor screenNameExtractor = ScreenNameExtractor.DEFAULT;
AppStartupTimer startupTimer;
VisibleScreenTracker visibleScreenTracker;
AppStartupTimer startupTimer = INVALID_TIMER;
VisibleScreenTracker visibleScreenTracker = INVALID_SCREEN_TRACKER;
Function<Tracer, Tracer> tracerCustomizer = Function.identity();

public AndroidLifecycleInstrumentationBuilder setStartupTimer(AppStartupTimer timer) {
Expand All @@ -41,6 +43,12 @@ public AndroidLifecycleInstrumentationBuilder setScreenNameExtractor(
}

public AndroidLifecycleInstrumentation build() {
if (visibleScreenTracker == INVALID_SCREEN_TRACKER) {
throw new IllegalStateException("visibleScreenTracker must be configured.");
}
if (startupTimer == INVALID_TIMER) {
throw new IllegalStateException("startupTimer must be configured.");
}
return new AndroidLifecycleInstrumentation(this);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -54,9 +54,7 @@ public Span start(Tracer tracer) {
return appStart;
}

/**
* @return epoch timestamp in nanos calculated by the startupClock.
*/
/** Returns the epoch timestamp in nanos calculated by the startupClock. */
public long clockNow() {
return startupClock.now();
}
Expand Down

0 comments on commit 257aeb3

Please sign in to comment.