Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions .fossa.yml
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,9 @@ targets:
- type: gradle
path: ./
target: ':instrumentation:apache-dubbo-2.7:library-autoconfigure'
- type: gradle
path: ./
target: ':instrumentation:apache-elasticjob-3.0:javaagent'
- type: gradle
path: ./
target: ':instrumentation:apache-httpasyncclient-4.1:javaagent'
Expand Down
1 change: 1 addition & 0 deletions docs/supported-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ These are the supported libraries and frameworks:
| [Apache CXF JAX-WS](https://cxf.apache.org/) | 3.0+ (not including 4.0+ yet) | N/A | Provides `http.route` [2], Controller Spans [3] |
| [Apache DBCP](https://commons.apache.org/proper/commons-dbcp/) | 2.0+ | [opentelemetry-apache-dbcp-2.0](../instrumentation/apache-dbcp-2.0/library) | [Database Pool Metrics] |
| [Apache Dubbo](https://github.com/apache/dubbo/) | 2.7+ | [opentelemetry-apache-dubbo-2.7](../instrumentation/apache-dubbo-2.7/library-autoconfigure) | [RPC Client Spans], [RPC Server Spans] |
| [Apache ElasticJob](https://shardingsphere.apache.org/elasticjob/) | 3.0+ | N/A | none |
| [Apache HttpAsyncClient](https://hc.apache.org/index.html) | 4.1+ | N/A | [HTTP Client Spans], [HTTP Client Metrics] |
| [Apache HttpClient](https://hc.apache.org/index.html) | 2.0+ | [opentelemetry-apache-httpclient-4.3](../instrumentation/apache-httpclient/apache-httpclient-4.3/library),<br>[opentelemetry-apache-httpclient-5.2](../instrumentation/apache-httpclient/apache-httpclient-5.2/library) | [HTTP Client Spans], [HTTP Client Metrics] |
| [Apache ShenYu](https://shenyu.apache.org/) | 2.4+ | N/A | Provides `http.route` [2] |
Expand Down
5 changes: 5 additions & 0 deletions instrumentation/apache-elasticjob-3.0/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
# Settings for the Apache ElasticJob instrumentation

| System property | Type | Default | Description |
|-----------------------------------------------------------------------|---------|---------|-----------------------------------------------------|
| `otel.instrumentation.apache-elasticjob.experimental-span-attributes` | Boolean | `false` | Enable the capture of experimental span attributes. |
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
plugins {
id("otel.javaagent-instrumentation")
}

muzzle {
pass {
group.set("org.apache.shardingsphere.elasticjob")
module.set("elasticjob-lite-core")
versions.set("[3.0.0,)")
assertInverse.set(true)
}
}

dependencies {
library("org.apache.shardingsphere.elasticjob:elasticjob-lite-core:3.0.0")

testImplementation("org.apache.curator:curator-test:5.1.0")
}

tasks.withType<Test>().configureEach {
jvmArgs("-Dotel.instrumentation.apache-elasticjob.experimental-span-attributes=true")
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,65 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0;

import static io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0.ElasticJobSingletons.helper;
import static net.bytebuddy.matcher.ElementMatchers.isMethod;
import static net.bytebuddy.matcher.ElementMatchers.named;
import static net.bytebuddy.matcher.ElementMatchers.takesArgument;

import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.TypeTransformer;
import javax.annotation.Nullable;
import net.bytebuddy.asm.Advice;
import net.bytebuddy.description.type.TypeDescription;
import net.bytebuddy.matcher.ElementMatcher;
import org.apache.shardingsphere.elasticjob.api.ShardingContext;
import org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob;

public class DataflowJobExecutorInstrumentation implements TypeInstrumentation {

@Override
public ElementMatcher<TypeDescription> typeMatcher() {
return named("org.apache.shardingsphere.elasticjob.dataflow.executor.DataflowJobExecutor");
}

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
isMethod()
.and(named("process"))
.and(
takesArgument(
0, named("org.apache.shardingsphere.elasticjob.dataflow.job.DataflowJob")))
.and(
takesArgument(
3, named("org.apache.shardingsphere.elasticjob.api.ShardingContext"))),
DataflowJobExecutorInstrumentation.class.getName() + "$ProcessAdvice");
}

@SuppressWarnings("unused")
public static class ProcessAdvice {

@Nullable
@Advice.OnMethodEnter(suppress = Throwable.class)
public static ElasticJobHelper.ElasticJobScope onEnter(
@Advice.Argument(0) DataflowJob<?> elasticJob,
@Advice.Argument(3) ShardingContext shardingContext) {

ElasticJobProcessRequest request =
ElasticJobProcessRequest.create(
shardingContext, ElasticJobType.DATAFLOW, elasticJob.getClass(), "processData");

return helper().startSpan(request);
}

@Advice.OnMethodExit(onThrowable = Throwable.class, suppress = Throwable.class)
public static void onExit(
@Advice.Enter ElasticJobHelper.ElasticJobScope scope, @Advice.Thrown Throwable throwable) {
helper().endSpan(scope, throwable);
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0;

import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeAttributesGetter;
import javax.annotation.Nullable;

class ElasticJobCodeAttributesGetter implements CodeAttributesGetter<ElasticJobProcessRequest> {
@Nullable
@Override
public Class<?> getCodeClass(ElasticJobProcessRequest request) {
return request.getUserJobClass();
}

@Nullable
@Override
public String getMethodName(ElasticJobProcessRequest request) {
return request.getUserMethodName();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,57 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0;

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

import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.context.Context;
import io.opentelemetry.instrumentation.api.instrumenter.AttributesExtractor;
import javax.annotation.Nullable;

class ElasticJobExperimentalAttributeExtractor
implements AttributesExtractor<ElasticJobProcessRequest, Void> {

private static final AttributeKey<String> ELASTICJOB_JOB_NAME =
stringKey("scheduling.apache-elasticjob.job.name");
private static final AttributeKey<String> ELASTICJOB_TASK_ID =
stringKey("scheduling.apache-elasticjob.task.id");
private static final AttributeKey<Long> ELASTICJOB_SHARDING_ITEM_INDEX =
longKey("scheduling.apache-elasticjob.sharding.item.index");
private static final AttributeKey<Long> ELASTICJOB_SHARDING_TOTAL_COUNT =
longKey("scheduling.apache-elasticjob.sharding.total.count");
private static final AttributeKey<String> ELASTICJOB_SHARDING_ITEM_PARAMETER =
stringKey("scheduling.apache-elasticjob.sharding.item.parameter");
private static final AttributeKey<String> ELASTICJOB_JOB_TYPE =
stringKey("scheduling.apache-elasticjob.job.type");

@Override
public void onStart(
AttributesBuilder attributes,
Context parentContext,
ElasticJobProcessRequest elasticJobProcessRequest) {
attributes.put(ELASTICJOB_JOB_NAME, elasticJobProcessRequest.getJobName());
attributes.put(ELASTICJOB_TASK_ID, elasticJobProcessRequest.getTaskId());
attributes.put(ELASTICJOB_SHARDING_ITEM_INDEX, elasticJobProcessRequest.getShardingItemIndex());
attributes.put(
ELASTICJOB_SHARDING_TOTAL_COUNT, elasticJobProcessRequest.getShardingTotalCount());
attributes.put(ELASTICJOB_JOB_TYPE, elasticJobProcessRequest.getJobType().name());
String shardingItemParameter = elasticJobProcessRequest.getShardingItemParameter();
if (shardingItemParameter != null) {
attributes.put(ELASTICJOB_SHARDING_ITEM_PARAMETER, shardingItemParameter);
}
}

@Override
public void onEnd(
AttributesBuilder attributes,
Context context,
ElasticJobProcessRequest elasticJobProcessRequest,
@Nullable Void unused,
@Nullable Throwable error) {}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0;

import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.instrumentation.api.instrumenter.Instrumenter;
import javax.annotation.Nullable;

public final class ElasticJobHelper {
private final Instrumenter<ElasticJobProcessRequest, Void> instrumenter;

private ElasticJobHelper(Instrumenter<ElasticJobProcessRequest, Void> instrumenter) {
this.instrumenter = instrumenter;
}

public static ElasticJobHelper create(Instrumenter<ElasticJobProcessRequest, Void> instrumenter) {
return new ElasticJobHelper(instrumenter);
}

@Nullable
public ElasticJobScope startSpan(ElasticJobProcessRequest request) {
Context parentContext = Context.current();
if (!this.instrumenter.shouldStart(parentContext, request)) {
return null;
}
Context context = this.instrumenter.start(parentContext, request);
return new ElasticJobScope(request, context, context.makeCurrent());
}

public void endSpan(@Nullable ElasticJobScope scope, @Nullable Throwable throwable) {
if (scope != null) {
scope.scope.close();
this.instrumenter.end(scope.context, scope.request, null, throwable);
}
}

public static class ElasticJobScope {
private final ElasticJobProcessRequest request;
private final Context context;
private final Scope scope;

private ElasticJobScope(ElasticJobProcessRequest request, Context context, Scope scope) {
this.request = request;
this.context = context;
this.scope = scope;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,37 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0;

import static java.util.Arrays.asList;

import com.google.auto.service.AutoService;
import io.opentelemetry.javaagent.extension.instrumentation.InstrumentationModule;
import io.opentelemetry.javaagent.extension.instrumentation.TypeInstrumentation;
import io.opentelemetry.javaagent.extension.instrumentation.internal.ExperimentalInstrumentationModule;
import java.util.List;

@AutoService(InstrumentationModule.class)
public class ElasticJobInstrumentationModule extends InstrumentationModule
implements ExperimentalInstrumentationModule {

public ElasticJobInstrumentationModule() {
super("apache-elasticjob", "apache-elasticjob-3.0");
}

@Override
public List<TypeInstrumentation> typeInstrumentations() {
return asList(
new SimpleJobExecutorInstrumentation(),
new DataflowJobExecutorInstrumentation(),
new ScriptJobExecutorInstrumentation(),
new HttpJobExecutorInstrumentation());
}

@Override
public boolean isIndyReady() {
return true;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,78 @@
/*
* Copyright The OpenTelemetry Authors
* SPDX-License-Identifier: Apache-2.0
*/

package io.opentelemetry.javaagent.instrumentation.apacheelasticjob.v3_0;

import org.apache.shardingsphere.elasticjob.api.ShardingContext;

public final class ElasticJobProcessRequest {
private final String jobName;
private final String taskId;
private final int shardingItemIndex;
private final int shardingTotalCount;
private final String shardingItemParameter;
private final ElasticJobType jobType;
private final Class<?> userJobClass;
private final String userMethodName;

private ElasticJobProcessRequest(
ShardingContext shardingContext,
ElasticJobType jobType,
Class<?> userJobClass,
String userMethodNam) {
this.jobName = shardingContext.getJobName();
this.taskId = shardingContext.getTaskId();
this.shardingItemIndex = shardingContext.getShardingItem();
this.shardingTotalCount = shardingContext.getShardingTotalCount();
this.shardingItemParameter = emptyToNull(shardingContext.getShardingParameter());
this.jobType = jobType;
this.userJobClass = userJobClass;
this.userMethodName = userMethodNam;
}

private static String emptyToNull(String string) {
return string == null || string.isEmpty() ? null : string;
}

public static ElasticJobProcessRequest create(
ShardingContext shardingContext,
ElasticJobType jobType,
Class<?> userJobClass,
String userMethodName) {
return new ElasticJobProcessRequest(shardingContext, jobType, userJobClass, userMethodName);
}

public String getJobName() {
return this.jobName;
}

public String getTaskId() {
return this.taskId;
}

public int getShardingItemIndex() {
return this.shardingItemIndex;
}

public int getShardingTotalCount() {
return this.shardingTotalCount;
}

public String getShardingItemParameter() {
return this.shardingItemParameter;
}

public ElasticJobType getJobType() {
return this.jobType;
}

public Class<?> getUserJobClass() {
return this.userJobClass;
}

public String getUserMethodName() {
return this.userMethodName;
}
}
Loading
Loading