Skip to content

Commit

Permalink
simplify cloud resources (#260)
Browse files Browse the repository at this point in the history
  • Loading branch information
SylvainJuge authored May 16, 2024
1 parent 093b34f commit a233a38
Show file tree
Hide file tree
Showing 10 changed files with 199 additions and 226 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@
*/
package co.elastic.otel;

import co.elastic.otel.resources.ElasticResourceProvider;
import com.google.auto.service.AutoService;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizer;
import io.opentelemetry.sdk.autoconfigure.spi.AutoConfigurationCustomizerProvider;
Expand All @@ -37,16 +36,6 @@ public class ElasticAutoConfigurationCustomizerprovider
public void customize(AutoConfigurationCustomizer autoConfiguration) {

autoConfiguration
.addResourceCustomizer(
(resource, configProperties) -> {
// create the resource provider ourselves we can store a reference to it
// and that will only get "fast" resources attributes when invoked
ElasticResourceProvider resourceProvider = new ElasticResourceProvider();

ElasticExtension.INSTANCE.registerResourceProvider(
resourceProvider, configProperties);
return resource.merge(resourceProvider.createResource(configProperties));
})
.addTracerProviderCustomizer(
(sdkTracerProviderBuilder, configProperties) ->
// span processor registration
Expand All @@ -59,29 +48,13 @@ public void customize(AutoConfigurationCustomizer autoConfiguration) {

// disabling embedded resource providers

// App server, loaded through SPI by default
disabledConfig.add(
"io.opentelemetry.contrib.resourceproviders.AppServerServiceNameProvider");

// GCP, SPI loading disabled but ensures disabled even if configured otherwise
disabledConfig.add("io.opentelemetry.contrib.gcp.resource.GCPResourceProvider");

// AWS, SPI loading disabled but ensures disabled even if configured otherwise
disabledConfig.add("io.opentelemetry.contrib.aws.resource.BeanstalkResourceProvider");
disabledConfig.add("io.opentelemetry.contrib.aws.resource.Ec2ResourceProvider");
disabledConfig.add("io.opentelemetry.contrib.aws.resource.EcsResourceProvider");
disabledConfig.add("io.opentelemetry.contrib.aws.resource.EksResourceProvider");
disabledConfig.add("io.opentelemetry.contrib.aws.resource.LambdaResourceProvider");

// disable upstream distro name & version provider
disabledConfig.add(
"io.opentelemetry.javaagent.tooling.DistroVersionResourceProvider");

Map<String, String> config = new HashMap<>();
config.put(DISABLED_RESOURCE_PROVIDERS, String.join(",", disabledConfig));

// disable loading expensive resource providers when invoked
config.put(ElasticResourceProvider.SKIP_EXPENSIVE_RESOURCE_PROVIDERS, "true");
return config;
})
.addSpanExporterCustomizer(
Expand Down
39 changes: 0 additions & 39 deletions custom/src/main/java/co/elastic/otel/ElasticExtension.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,36 +19,19 @@
package co.elastic.otel;

import co.elastic.otel.common.util.ExecutorUtils;
import co.elastic.otel.resources.ElasticResourceProvider;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.context.internal.shaded.WeakConcurrentMap;
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.SpanProcessor;
import io.opentelemetry.sdk.trace.export.SpanExporter;
import java.util.Objects;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.Future;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.logging.Level;
import java.util.logging.Logger;

public class ElasticExtension {

private static final Logger logger = Logger.getLogger(ElasticExtension.class.getName());

public static final ElasticExtension INSTANCE = new ElasticExtension();
private final ElasticBreakdownMetrics breakdownMetrics;
private final ElasticSpanProcessor spanProcessor;
private final ExecutorService asyncInitExecutor;
private ElasticSpanExporter spanExporter;
private WeakConcurrentMap<Resource, Resource> cachedResources =
new WeakConcurrentMap.WithInlinedExpunction<>();
private Resource extraResource;
private Future<Resource> resourceFuture;

private ElasticExtension() {
this.breakdownMetrics = new ElasticBreakdownMetrics();
Expand All @@ -73,28 +56,6 @@ public SpanExporter wrapSpanExporter(SpanExporter toWrap) {
return spanExporter;
}

public void registerResourceProvider(
ElasticResourceProvider resourceProvider, ConfigProperties config) {
this.resourceFuture = asyncInitExecutor.submit(() -> resourceProvider.getExtraResource(config));
}

public Resource wrapResource(Resource resource) {
// because original resources are immutable
Resource result = cachedResources.get(resource);
if (result != null) {
return result;
}
Objects.requireNonNull(resourceFuture);
try {
extraResource = resourceFuture.get(5, TimeUnit.SECONDS);
result = resource.merge(extraResource);
cachedResources.put(resource, result);
} catch (InterruptedException | ExecutionException | TimeoutException e) {
logger.log(Level.WARNING, "unable capture resource attributes", e);
}
return result;
}

public void shutdown() {
ExecutorUtils.shutdownAndWaitTermination(asyncInitExecutor);
}
Expand Down
16 changes: 1 addition & 15 deletions custom/src/main/java/co/elastic/otel/ElasticMetricExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -18,17 +18,13 @@
*/
package co.elastic.otel;

import co.elastic.otel.metrics.DelegatingMetricData;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.metrics.Aggregation;
import io.opentelemetry.sdk.metrics.InstrumentType;
import io.opentelemetry.sdk.metrics.data.AggregationTemporality;
import io.opentelemetry.sdk.metrics.data.MetricData;
import io.opentelemetry.sdk.metrics.export.MetricExporter;
import io.opentelemetry.sdk.resources.Resource;
import java.util.ArrayList;
import java.util.Collection;
import java.util.List;

public class ElasticMetricExporter implements MetricExporter {

Expand All @@ -50,17 +46,7 @@ public Aggregation getDefaultAggregation(InstrumentType instrumentType) {

@Override
public CompletableResultCode export(Collection<MetricData> metrics) {
List<MetricData> toSend = new ArrayList<>(metrics.size());
for (MetricData metric : metrics) {
toSend.add(
new DelegatingMetricData(metric) {
@Override
public Resource getResource() {
return ElasticExtension.INSTANCE.wrapResource(super.getResource());
}
});
}
return delegate.export(toSend);
return delegate.export(metrics);
}

@Override
Expand Down
6 changes: 0 additions & 6 deletions custom/src/main/java/co/elastic/otel/ElasticSpanExporter.java
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.sdk.common.CompletableResultCode;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.trace.data.DelegatingSpanData;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.export.SpanExporter;
Expand Down Expand Up @@ -66,11 +65,6 @@ public CompletableResultCode export(Collection<SpanData> spans) {
public Attributes getAttributes() {
return newAttributes;
}

@Override
public Resource getResource() {
return ElasticExtension.INSTANCE.wrapResource(span.getResource());
}
});
}
}
Expand Down
41 changes: 41 additions & 0 deletions licenses/HdrHistogram-2.2.1.jar/META-INF/LICENSE.txt
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
The code in this repository code was Written by Gil Tene, Michael Barker,
and Matt Warren, and released to the public domain, as explained at
http://creativecommons.org/publicdomain/zero/1.0/

For users of this code who wish to consume it under the "BSD" license
rather than under the public domain or CC0 contribution text mentioned
above, the code found under this directory is *also* provided under the
following license (commonly referred to as the BSD 2-Clause License). This
license does not detract from the above stated release of the code into
the public domain, and simply represents an additional license granted by
the Author.

-----------------------------------------------------------------------------
** Beginning of "BSD 2-Clause License" text. **

Copyright (c) 2012, 2013, 2014, 2015, 2016 Gil Tene
Copyright (c) 2014 Michael Barker
Copyright (c) 2014 Matt Warren
All rights reserved.

Redistribution and use in source and binary forms, with or without
modification, are permitted provided that the following conditions are met:

1. Redistributions of source code must retain the above copyright notice,
this list of conditions and the following disclaimer.

2. Redistributions in binary form must reproduce the above copyright notice,
this list of conditions and the following disclaimer in the documentation
and/or other materials provided with the distribution.

THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS"
AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE
LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF
THE POSSIBILITY OF SUCH DAMAGE.
41 changes: 18 additions & 23 deletions licenses/more-licences.md
Original file line number Diff line number Diff line change
Expand Up @@ -58,99 +58,94 @@
> - **POM Project URL**: [https://github.com/open-telemetry/opentelemetry-java](https://github.com/open-telemetry/opentelemetry-java)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
**14** **Group:** `io.opentelemetry.contrib` **Name:** `opentelemetry-aws-resources` **Version:** `1.34.0-alpha`
> - **POM Project URL**: [https://github.com/open-telemetry/opentelemetry-java-contrib](https://github.com/open-telemetry/opentelemetry-java-contrib)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
**15** **Group:** `io.opentelemetry.contrib` **Name:** `opentelemetry-gcp-resources` **Version:** `1.34.0-alpha`
> - **POM Project URL**: [https://github.com/open-telemetry/opentelemetry-java-contrib](https://github.com/open-telemetry/opentelemetry-java-contrib)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
**16** **Group:** `io.opentelemetry.contrib` **Name:** `opentelemetry-resource-providers` **Version:** `1.34.0-alpha`
**14** **Group:** `io.opentelemetry.contrib` **Name:** `opentelemetry-resource-providers` **Version:** `1.34.0-alpha`
> - **POM Project URL**: [https://github.com/open-telemetry/opentelemetry-java-contrib](https://github.com/open-telemetry/opentelemetry-java-contrib)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
**17** **Group:** `io.opentelemetry.javaagent` **Name:** `opentelemetry-javaagent-extension-api` **Version:** `2.3.0-alpha`
**15** **Group:** `io.opentelemetry.javaagent` **Name:** `opentelemetry-javaagent-extension-api` **Version:** `2.3.0-alpha`
> - **POM Project URL**: [https://github.com/open-telemetry/opentelemetry-java-instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
**18** **Group:** `io.opentelemetry.javaagent` **Name:** `opentelemetry-javaagent-tooling` **Version:** `2.3.0-alpha`
**16** **Group:** `io.opentelemetry.javaagent` **Name:** `opentelemetry-javaagent-tooling` **Version:** `2.3.0-alpha`
> - **POM Project URL**: [https://github.com/open-telemetry/opentelemetry-java-instrumentation](https://github.com/open-telemetry/opentelemetry-java-instrumentation)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
**19** **Group:** `io.opentelemetry.semconv` **Name:** `opentelemetry-semconv` **Version:** `1.25.0-alpha`
**17** **Group:** `io.opentelemetry.semconv` **Name:** `opentelemetry-semconv` **Version:** `1.25.0-alpha`
> - **POM Project URL**: [https://github.com/open-telemetry/semantic-conventions-java](https://github.com/open-telemetry/semantic-conventions-java)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
**20** **Group:** `io.opentelemetry.semconv` **Name:** `opentelemetry-semconv-incubating` **Version:** `1.25.0-alpha`
**18** **Group:** `io.opentelemetry.semconv` **Name:** `opentelemetry-semconv-incubating` **Version:** `1.25.0-alpha`
> - **POM Project URL**: [https://github.com/open-telemetry/semantic-conventions-java](https://github.com/open-telemetry/semantic-conventions-java)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
**21** **Group:** `net.bytebuddy` **Name:** `byte-buddy-dep` **Version:** `1.14.13`
**19** **Group:** `net.bytebuddy` **Name:** `byte-buddy-dep` **Version:** `1.14.13`
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
> - **Embedded license files**: [byte-buddy-dep-1.14.13.jar/META-INF/LICENSE](byte-buddy-dep-1.14.13.jar/META-INF/LICENSE)
- [byte-buddy-dep-1.14.13.jar/META-INF/NOTICE](byte-buddy-dep-1.14.13.jar/META-INF/NOTICE)

**22** **Group:** `org.jctools` **Name:** `jctools-core` **Version:** `4.0.3`
**20** **Group:** `org.jctools` **Name:** `jctools-core` **Version:** `4.0.3`
> - **Manifest License**: Apache License, Version 2.0 (Not Packaged)
> - **POM Project URL**: [https://github.com/JCTools](https://github.com/JCTools)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
**23** **Group:** `org.ow2.asm` **Name:** `asm` **Version:** `9.6`
**21** **Group:** `org.ow2.asm` **Name:** `asm` **Version:** `9.6`
> - **Manifest Project URL**: [http://asm.ow2.org](http://asm.ow2.org)
> - **Manifest License**: The 3-Clause BSD License (Not Packaged)
> - **POM Project URL**: [http://asm.ow2.io/](http://asm.ow2.io/)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
> - **POM License**: The 3-Clause BSD License - [https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)
**24** **Group:** `org.ow2.asm` **Name:** `asm-commons` **Version:** `9.6`
**22** **Group:** `org.ow2.asm` **Name:** `asm-commons` **Version:** `9.6`
> - **Manifest Project URL**: [http://asm.ow2.org](http://asm.ow2.org)
> - **Manifest License**: The 3-Clause BSD License (Not Packaged)
> - **POM Project URL**: [http://asm.ow2.io/](http://asm.ow2.io/)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
> - **POM License**: The 3-Clause BSD License - [https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)
**25** **Group:** `tools.profiler` **Name:** `async-profiler` **Version:** `3.0`
**23** **Group:** `tools.profiler` **Name:** `async-profiler` **Version:** `3.0`
> - **POM Project URL**: [https://profiler.tools](https://profiler.tools)
> - **POM License**: Apache License, Version 2.0 - [https://www.apache.org/licenses/LICENSE-2.0](https://www.apache.org/licenses/LICENSE-2.0)
## Creative Commons Legal Code

**26** **Group:** `org.hdrhistogram` **Name:** `HdrHistogram` **Version:** `2.1.12`
**24** **Group:** `org.hdrhistogram` **Name:** `HdrHistogram` **Version:** `2.2.1`
> - **Manifest License**: The 2-Clause BSD License (Not Packaged)
> - **POM Project URL**: [http://hdrhistogram.github.io/HdrHistogram/](http://hdrhistogram.github.io/HdrHistogram/)
> - **POM License**: Creative Commons Legal Code - [https://creativecommons.org/publicdomain/zero/1.0/legalcode](https://creativecommons.org/publicdomain/zero/1.0/legalcode)
> - **POM License**: PUBLIC DOMAIN - [http://creativecommons.org/publicdomain/zero/1.0/](http://creativecommons.org/publicdomain/zero/1.0/)
> - **POM License**: The 2-Clause BSD License - [https://opensource.org/licenses/BSD-2-Clause](https://opensource.org/licenses/BSD-2-Clause)
> - **Embedded license files**: [HdrHistogram-2.2.1.jar/META-INF/LICENSE.txt](HdrHistogram-2.2.1.jar/META-INF/LICENSE.txt)
## PUBLIC DOMAIN

**27** **Group:** `org.hdrhistogram` **Name:** `HdrHistogram` **Version:** `2.1.12`
**25** **Group:** `org.hdrhistogram` **Name:** `HdrHistogram` **Version:** `2.2.1`
> - **Manifest License**: The 2-Clause BSD License (Not Packaged)
> - **POM Project URL**: [http://hdrhistogram.github.io/HdrHistogram/](http://hdrhistogram.github.io/HdrHistogram/)
> - **POM License**: Creative Commons Legal Code - [https://creativecommons.org/publicdomain/zero/1.0/legalcode](https://creativecommons.org/publicdomain/zero/1.0/legalcode)
> - **POM License**: PUBLIC DOMAIN - [http://creativecommons.org/publicdomain/zero/1.0/](http://creativecommons.org/publicdomain/zero/1.0/)
> - **POM License**: The 2-Clause BSD License - [https://opensource.org/licenses/BSD-2-Clause](https://opensource.org/licenses/BSD-2-Clause)
> - **Embedded license files**: [HdrHistogram-2.2.1.jar/META-INF/LICENSE.txt](HdrHistogram-2.2.1.jar/META-INF/LICENSE.txt)
## The 2-Clause BSD License

**28** **Group:** `org.hdrhistogram` **Name:** `HdrHistogram` **Version:** `2.1.12`
**26** **Group:** `org.hdrhistogram` **Name:** `HdrHistogram` **Version:** `2.2.1`
> - **Manifest License**: The 2-Clause BSD License (Not Packaged)
> - **POM Project URL**: [http://hdrhistogram.github.io/HdrHistogram/](http://hdrhistogram.github.io/HdrHistogram/)
> - **POM License**: Creative Commons Legal Code - [https://creativecommons.org/publicdomain/zero/1.0/legalcode](https://creativecommons.org/publicdomain/zero/1.0/legalcode)
> - **POM License**: PUBLIC DOMAIN - [http://creativecommons.org/publicdomain/zero/1.0/](http://creativecommons.org/publicdomain/zero/1.0/)
> - **POM License**: The 2-Clause BSD License - [https://opensource.org/licenses/BSD-2-Clause](https://opensource.org/licenses/BSD-2-Clause)
> - **Embedded license files**: [HdrHistogram-2.2.1.jar/META-INF/LICENSE.txt](HdrHistogram-2.2.1.jar/META-INF/LICENSE.txt)
## The 3-Clause BSD License

**29** **Group:** `org.ow2.asm` **Name:** `asm` **Version:** `9.6`
**27** **Group:** `org.ow2.asm` **Name:** `asm` **Version:** `9.6`
> - **Manifest Project URL**: [http://asm.ow2.org](http://asm.ow2.org)
> - **Manifest License**: The 3-Clause BSD License (Not Packaged)
> - **POM Project URL**: [http://asm.ow2.io/](http://asm.ow2.io/)
> - **POM License**: Apache License, Version 2.0 - [http://www.apache.org/licenses/LICENSE-2.0](http://www.apache.org/licenses/LICENSE-2.0)
> - **POM License**: The 3-Clause BSD License - [https://opensource.org/licenses/BSD-3-Clause](https://opensource.org/licenses/BSD-3-Clause)
**30** **Group:** `org.ow2.asm` **Name:** `asm-commons` **Version:** `9.6`
**28** **Group:** `org.ow2.asm` **Name:** `asm-commons` **Version:** `9.6`
> - **Manifest Project URL**: [http://asm.ow2.org](http://asm.ow2.org)
> - **Manifest License**: The 3-Clause BSD License (Not Packaged)
> - **POM Project URL**: [http://asm.ow2.io/](http://asm.ow2.io/)
Expand Down
Loading

0 comments on commit a233a38

Please sign in to comment.