Skip to content

Conversation

@crossoverJie
Copy link
Member

Resolves #11921

@crossoverJie crossoverJie requested a review from a team August 22, 2024 15:16
@crossoverJie crossoverJie marked this pull request as draft August 22, 2024 15:29
@github-actions github-actions bot requested a review from theletterf August 22, 2024 15:31
@crossoverJie crossoverJie marked this pull request as ready for review August 23, 2024 12:19
@crossoverJie crossoverJie requested a review from steverao August 26, 2024 09:59
@crossoverJie
Copy link
Member Author

@laurit Please take a look.

@Override
public void transform(TypeTransformer transformer) {
transformer.applyAdviceToMethod(
named("process").and(isPublic()).and(takesArguments(1)),
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually we verify here that the argument type is what is expected in the advice

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import io.opentelemetry.instrumentation.api.incubator.semconv.code.CodeSpanNameExtractor;
import io.opentelemetry.instrumentation.api.instrumenter.SpanNameExtractor;

class PowerJobSpanNameExtractor implements SpanNameExtractor<PowerJobProcessRequest> {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

might as well delete this and just use CodeSpanNameExtractor

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import io.opentelemetry.instrumentation.api.instrumenter.InstrumenterBuilder;
import io.opentelemetry.javaagent.bootstrap.internal.AgentInstrumentationConfig;

public final class PowerJobInstrumenterFactory {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd merge the code from this class into PowerJobSingletons

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 62 to 67
span.hasName(String.format("%s.process", TestBasicProcessor.class.getSimpleName()));
span.hasKind(SpanKind.INTERNAL);
span.hasStatus(StatusData.unset());
span.hasAttributesSatisfying(
attributeAssertions(
TestBasicProcessor.class.getName(), jobId, jobParam, BASIC_PROCESSOR));
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

assertions can be chained span.hasName().hasKind()...

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

span.hasName(String.format("%s.process", TestBasicProcessor.class.getSimpleName()));
span.hasKind(SpanKind.INTERNAL);
span.hasStatus(StatusData.unset());
span.hasAttributesSatisfying(
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

usually we use hasAttributesSatisfyingExactly

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 13 to 23
public static final String BROADCAST_PROCESSOR = "BroadcastProcessor";
public static final String MAP_PROCESSOR = "MapProcessor";
public static final String MAP_REDUCE_PROCESSOR = "MapReduceProcessor";

// Official processors
public static final String SHELL_PROCESSOR = "ShellProcessor";
public static final String PYTHON_PROCESSOR = "PythonProcessor";
public static final String HTTP_PROCESSOR = "HttpProcessor";
public static final String FILE_CLEANUP_PROCESSOR = "FileCleanupProcessor";
public static final String SPRING_DATASOURCE_SQL_PROCESSOR = "SpringDatasourceSqlProcessor";
public static final String DYNAMIC_DATASOURCE_SQL_PROCESSOR = "DynamicDatasourceSqlProcessor";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

These are only used in the tests, you could move them there or inline them.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done


private PowerJobConstants() {}

public static final String BASIC_PROCESSOR = "BasicProcessor";
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

perhaps move it to the class that uses it, imo no need to have a separate class for 1 constant.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 49 to 51
if (failedStatusPredicate.test(result)) {
request.setFailed();
}
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Usually we'd just pass the result as response to the instrumenter then in the span status extractor you could just use result.isSuccess() without the need to pass failedStatusPredicate around.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

import java.util.function.Predicate;
import tech.powerjob.worker.core.processor.ProcessResult;

public final class PowerJobHelper {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd just inline the startSpan and endSpan methods. The instrumentations that use a similar helper class are usually more complicated.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for your suggestion, I will streamline the code.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

Comment on lines 24 to 27
private String methodName;
private final Long jobId;
private String jobType;
private Class<?> declaringClass;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think you could make all of these final

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done

.addAttributesExtractor(CodeAttributesExtractor.create(codeAttributesGetter))
.setSpanStatusExtractor(
(spanStatusBuilder, powerJobProcessRequest, response, error) -> {
if (error != null || response == null || !response.isSuccess()) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think your original code did not set the status to error when response == null, could you verify whether this is the intended behavior. Perhaps you meant response != null && !response.isSuccess().
Most of the status extractors follow a pattern where they delegate to the default status extractor. Currently it doesn't change anything because the default extractor also just checks error != null, but still I think it would be nice to follow the same pattern

if (response != null && !response.isSuccess()) {
  spanStatusBuilder.setStatus(StatusCode.ERROR);
} else {
  SpanStatusExtractor.getDefault().extract(spanStatusBuilder, powerJobProcessRequest, response, error);
}

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

thank you for your suggestion

@crossoverJie crossoverJie reopened this Sep 6, 2024
@crossoverJie crossoverJie requested a review from laurit September 6, 2024 10:07
@laurit laurit added this to the v2.8.0 milestone Sep 6, 2024
@trask trask merged commit 844c28c into open-telemetry:main Sep 12, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Add Support for the PowerJob

5 participants