Skip to content

Commit

Permalink
spotless
Browse files Browse the repository at this point in the history
  • Loading branch information
breedx-splk committed Dec 7, 2023
1 parent 6eb0330 commit 598efc9
Show file tree
Hide file tree
Showing 5 changed files with 54 additions and 30 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -22,14 +22,13 @@
import static com.splunk.rum.SplunkRum.COMPONENT_KEY;
import static com.splunk.rum.SplunkRum.COMPONENT_UI;
import static com.splunk.rum.SplunkRum.RUM_TRACER_NAME;
import static java.util.Objects.requireNonNull;
import static io.opentelemetry.android.RumConstants.APP_START_SPAN_NAME;
import static io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor.constant;
import static io.opentelemetry.semconv.ResourceAttributes.DEPLOYMENT_ENVIRONMENT;
import static java.util.Objects.requireNonNull;

import android.app.Application;
import android.os.Looper;

import androidx.annotation.NonNull;
import androidx.annotation.Nullable;
import com.splunk.rum.internal.UInt32QuadXorTraceIdRatioSampler;
Expand Down Expand Up @@ -96,7 +95,8 @@ SplunkRum initialize(
initializationEvents.begin();

OtelRumConfig config = new OtelRumConfig();
GlobalAttributesSupplier globalAttributeSupplier = new GlobalAttributesSupplier(builder.globalAttributes);
GlobalAttributesSupplier globalAttributeSupplier =
new GlobalAttributesSupplier(builder.globalAttributes);
config.setGlobalAttributes(globalAttributeSupplier);

OpenTelemetryRumBuilder otelRumBuilder = OpenTelemetryRum.builder(application, config);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,9 +26,7 @@
import android.util.Log;
import android.webkit.WebView;
import androidx.annotation.Nullable;

import com.splunk.rum.internal.GlobalAttributesSupplier;

import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider;
import io.opentelemetry.android.instrumentation.startup.AppStartupTimer;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,22 +1,37 @@
package com.splunk.rum.internal;
/*
* Copyright Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import java.util.function.Consumer;
import java.util.function.Supplier;
package com.splunk.rum.internal;

import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
* Class to hold and update the set of global attributes that are appended to each
* span. This is used as the supplier to the GlobalAttributesSpanAppender. We need this
* because SplunkRum exposes a topmost update() method, and we can't break that contract,
* and there's no way to get a reference to the GlobalAttributesSpanAppender created by OtelRum.
* Class to hold and update the set of global attributes that are appended to each span. This is
* used as the supplier to the GlobalAttributesSpanAppender. We need this because SplunkRum exposes
* a topmost update() method, and we can't break that contract, and there's no way to get a
* reference to the GlobalAttributesSpanAppender created by OtelRum.
*
* <p>
* When global attributes are more fleshed out in upstream, this will hopefully improve or go away.
* <p>When global attributes are more fleshed out in upstream, this will hopefully improve or go
* away.
*
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
* <p>This class is internal and is hence not for public use. Its APIs are unstable and can change
* at any time.
*/
public class GlobalAttributesSupplier implements Supplier<Attributes> {
private Attributes attributes;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -36,10 +36,7 @@
import android.content.Context;
import android.location.Location;
import android.webkit.WebView;

import com.splunk.rum.internal.GlobalAttributesSupplier;

import io.opentelemetry.android.GlobalAttributesSpanAppender;
import io.opentelemetry.android.OpenTelemetryRum;
import io.opentelemetry.android.instrumentation.network.CurrentNetworkProvider;
import io.opentelemetry.api.common.Attributes;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,27 +1,41 @@
package com.splunk.rum.internal;
/*
* Copyright Splunk Inc.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/

import static org.junit.jupiter.api.Assertions.*;
package com.splunk.rum.internal;

import static io.opentelemetry.api.common.AttributeKey.stringKey;

import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;

import io.opentelemetry.api.common.Attributes;
import org.junit.jupiter.api.Test;

class GlobalAttributesSupplierTest {

@Test
void update(){
void update() {
Attributes initial = Attributes.of(stringKey("foo"), "bar", stringKey("bar"), "baz");
GlobalAttributesSupplier testClass = new GlobalAttributesSupplier(initial);
testClass.update(builder -> {
builder.put("jimbo", "hutch");
builder.remove(stringKey("bar"));
});
testClass.update(
builder -> {
builder.put("jimbo", "hutch");
builder.remove(stringKey("bar"));
});
Attributes result = testClass.get();
assertEquals("bar", result.get(stringKey("foo")));
assertEquals("hutch", result.get(stringKey("jimbo")));
assertNull(result.get(stringKey("bar")));
}

}
}

0 comments on commit 598efc9

Please sign in to comment.