Skip to content

Commit

Permalink
Merge branch 'open-telemetry:main' into develop/add-resource-attributes
Browse files Browse the repository at this point in the history
  • Loading branch information
surbhiia authored Aug 29, 2023
2 parents 854b387 + 0781e61 commit a54c1a2
Show file tree
Hide file tree
Showing 9 changed files with 71 additions and 24 deletions.
2 changes: 2 additions & 0 deletions .github/repository-settings.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,7 @@ settings](https://github.com/open-telemetry/community/blob/main/docs/how-to-conf

## Secrets and variables > Actions

* `GPG_PASSWORD` - stored in OpenTelemetry-Java 1Password
* `GPG_PRIVATE_KEY` - stored in OpenTelemetry-Java 1Password
* `SONATYPE_KEY` - owned by [@breedx-splk](https://github.com/breedx-splk)
* `SONATYPE_USER` - owned by [@breedx-splk](https://github.com/breedx-splk)
18 changes: 18 additions & 0 deletions buildSrc/src/main/kotlin/otel.errorprone-conventions.gradle.kts
Original file line number Diff line number Diff line change
@@ -1,4 +1,6 @@
import com.android.build.api.variant.AndroidComponentsExtension
import net.ltgt.gradle.errorprone.CheckSeverity
import net.ltgt.gradle.errorprone.ErrorPronePlugin
import net.ltgt.gradle.errorprone.errorprone
import net.ltgt.gradle.nullaway.nullaway
import java.util.Locale
Expand All @@ -8,6 +10,16 @@ plugins {
id("net.ltgt.nullaway")
}


val isAndroidProject = extensions.findByName("android") != null

if (isAndroidProject) {
val errorProneConfig = configurations.getByName(ErrorPronePlugin.CONFIGURATION_NAME)
extensions.getByType(AndroidComponentsExtension::class.java).onVariants {
it.annotationProcessorConfiguration.extendsFrom(errorProneConfig)
}
}

dependencies {
errorprone("com.uber.nullaway:nullaway:0.10.12")
errorprone("com.google.errorprone:error_prone_core:2.21.1")
Expand All @@ -24,6 +36,12 @@ tasks {
if (name.lowercase(Locale.getDefault()).contains("test")) {
// just disable all error prone checks for test
isEnabled.set(false);
isCompilingTestOnlyCode.set(true)
} else {
if (isAndroidProject) {
isEnabled.set(true)
isCompilingTestOnlyCode.set(false)
}
}

nullaway {
Expand Down
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
6 changes: 6 additions & 0 deletions renovate.json5
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
"matchPackageNames": ["androidx.browser:browser"],
"matchUpdateTypes": ["major", "minor"],
"enabled": false
},
{
// somehow renovate gets confused by the android property in gradle.properties,
// so let's just exclude it and hopefully clean up the dashboard
"matchPackageNames": ["string:rum.version"],
"enabled": false
}
]
}

0 comments on commit a54c1a2

Please sign in to comment.