-
Notifications
You must be signed in to change notification settings - Fork 1
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 resource attributes lost moving ReconfigurableOpenTelemetry to opentelemetry-api-plugin #11
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,43 @@ | ||
/* | ||
* Copyright The Original Author or Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.jenkins.plugins.opentelemetry.api.instrumentation.resource; | ||
|
||
import io.jenkins.plugins.opentelemetry.api.semconv.JenkinsAttributes; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ConfigProperties; | ||
import io.opentelemetry.sdk.autoconfigure.spi.ResourceProvider; | ||
import io.opentelemetry.sdk.resources.Resource; | ||
import io.opentelemetry.sdk.resources.ResourceBuilder; | ||
import io.opentelemetry.semconv.ServiceAttributes; | ||
import io.opentelemetry.semconv.incubating.ServiceIncubatingAttributes; | ||
|
||
import java.util.Optional; | ||
import java.util.logging.Level; | ||
import java.util.logging.Logger; | ||
|
||
public class JenkinsResourceProvider implements ResourceProvider { | ||
private final static Logger LOGGER = Logger.getLogger(JenkinsResourceProvider.class.getName()); | ||
|
||
@Override | ||
public Resource createResource(ConfigProperties config) { | ||
ResourceBuilder resourceBuilder = Resource.builder(); | ||
resourceBuilder.put(ServiceAttributes.SERVICE_NAME, JenkinsAttributes.JENKINS); | ||
resourceBuilder.put(ServiceIncubatingAttributes.SERVICE_NAMESPACE, JenkinsAttributes.JENKINS); | ||
|
||
Optional<String> jenkinsVersion = Optional.ofNullable(config.getString(JenkinsAttributes.JENKINS_VERSION.getKey())); | ||
jenkinsVersion.ifPresent(version -> resourceBuilder.put(ServiceAttributes.SERVICE_VERSION, version)); | ||
// Report jenkins.version even if service.version is overriden | ||
jenkinsVersion.ifPresent(version -> resourceBuilder.put(JenkinsAttributes.JENKINS_VERSION.getKey(), version)); | ||
|
||
Optional<String> jenkinsUrl = Optional.ofNullable(config.getString(JenkinsAttributes.JENKINS_URL.getKey())); | ||
jenkinsUrl.ifPresent(version -> resourceBuilder.put(JenkinsAttributes.JENKINS_URL, version)); | ||
|
||
Optional<String> serviceInstanceId = Optional.ofNullable(config.getString(ServiceIncubatingAttributes.SERVICE_INSTANCE_ID.getKey())); | ||
serviceInstanceId.ifPresent(version -> resourceBuilder.put(ServiceIncubatingAttributes.SERVICE_INSTANCE_ID, version)); | ||
Resource resource = resourceBuilder.build(); | ||
LOGGER.log(Level.FINER, () -> "Jenkins resource: " + resource); | ||
return resource; | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,26 @@ | ||
/* | ||
* Copyright The Original Author or Authors | ||
* SPDX-License-Identifier: Apache-2.0 | ||
*/ | ||
|
||
package io.jenkins.plugins.opentelemetry.api.semconv; | ||
|
||
import io.opentelemetry.api.common.AttributeKey; | ||
import jenkins.model.Jenkins; | ||
|
||
/** | ||
* @see io.opentelemetry.api.common.Attributes | ||
* @see io.opentelemetry.semconv.ServiceAttributes | ||
*/ | ||
public class JenkinsAttributes { | ||
|
||
/** | ||
* @see Jenkins#getRootUrl() | ||
*/ | ||
public static final AttributeKey<String> JENKINS_URL = AttributeKey.stringKey("jenkins.url"); | ||
|
||
public static final String JENKINS = "jenkins"; | ||
|
||
public static final AttributeKey<String> JENKINS_VERSION = AttributeKey.stringKey("jenkins.version"); | ||
|
||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
io.jenkins.plugins.opentelemetry.api.instrumentation.resource.JenkinsResourceProvider |
Original file line number | Diff line number | Diff line change | ||||
---|---|---|---|---|---|---|
@@ -0,0 +1,18 @@ | ||||||
package io.jenkins.plugins.opentelemetry; | ||||||
|
||||||
import io.jenkins.plugins.opentelemetry.api.ReconfigurableOpenTelemetry; | ||||||
import io.opentelemetry.instrumentation.apachehttpclient.v4_3.ApacheHttpClientTelemetry; | ||||||
import org.apache.http.impl.client.CloseableHttpClient; | ||||||
import org.apache.http.impl.client.HttpClientBuilder; | ||||||
import org.junit.Test; | ||||||
|
||||||
public class ApacheHttpClientInstrumentationTest { | ||||||
|
||||||
@Test | ||||||
public void test_instantiate_instrumented_http_client() { | ||||||
ReconfigurableOpenTelemetry openTelemetry = new ReconfigurableOpenTelemetry(); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. should this be in a try-with-resources?
Suggested change
|
||||||
HttpClientBuilder httpClientBuilder = ApacheHttpClientTelemetry.create(openTelemetry).newHttpClientBuilder(); | ||||||
CloseableHttpClient httpClient = httpClientBuilder.build(); | ||||||
System.out.println(httpClient); | ||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to assert something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. yes verify we don't have class loading issues. I'll iterate on the test |
||||||
} | ||||||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,19 @@ | ||
package io.jenkins.plugins.opentelemetry; | ||
|
||
import io.jenkins.plugins.opentelemetry.api.ReconfigurableOpenTelemetry; | ||
import io.opentelemetry.instrumentation.jdbc.datasource.JdbcTelemetry; | ||
import org.apache.commons.dbcp2.BasicDataSource; | ||
import org.junit.Test; | ||
|
||
import javax.sql.DataSource; | ||
|
||
public class JdbcInstrumentationTest { | ||
|
||
@Test | ||
public void test_instantiate_instrumented_data_source() { | ||
try (ReconfigurableOpenTelemetry openTelemetry = new ReconfigurableOpenTelemetry()) { | ||
DataSource dataSource = JdbcTelemetry.create(openTelemetry).wrap(new BasicDataSource()); | ||
System.out.println(dataSource); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Is this supposed to assert something? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Ditto, verify class loading issues. I'll iterate on these tests |
||
} | ||
} | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We revert semconv to 1.25 as opentelemetry instrumentations have a dependency on semconv 1.25.