Skip to content
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

Support access the tracer context in spring gateway filter #539

Merged
merged 8 commits into from
Jul 7, 2023

Conversation

darknesstm
Copy link
Contributor

@darknesstm darknesstm commented May 26, 2023

CHANGES.md Show resolved Hide resolved
@wu-sheng wu-sheng changed the title Support access the sky-walking tracer context in spring gateway filter Support access the tracer context in spring gateway filter May 26, 2023
@wu-sheng
Copy link
Member

Hi, this feature should be good. But you instrument a lot of things, could you try to put a doc about why you are instrumenting? And why there are so many things have to be done?

@darknesstm
Copy link
Contributor Author

Hi, this feature should be good. But you instrument a lot of things, could you try to put a doc about why you are instrumenting? And why there are so many things have to be done?

I add a [Feature] issues linked to this.
The source is mainly based on the relevant source of apm-toolkit-trace, with some simple modifications.

@wu-sheng
Copy link
Member

I am not sure why, but this PR doesn't drive CI running.

@darknesstm
Copy link
Contributor Author

I am not sure why, but this PR doesn't drive CI running.

I also see the same problem in #541

@wu-sheng
Copy link
Member

No, it isn't. That PR is waiting for maintainers' approval to run. But your PR doesn't.

Yours
image

That PR
image

@darknesstm
Copy link
Contributor Author

It may be that the github actions of my account were banned before, and I didn't continue to pay attention without much impact, so I will submitted the a ticket and deal with that.

@kezhenxu94
Copy link
Member

You need to resolve conflicts before we can run the CI

@wu-sheng
Copy link
Member

wu-sheng commented Jun 1, 2023

You need to resolve conflicts before we can run the CI

There was no conflict, still not working.

@darknesstm
Copy link
Contributor Author

You need to resolve conflicts before we can run the CI

There was no conflict, still not working.

My Github Actions now works normally...

@wu-sheng
Copy link
Member

wu-sheng commented Jul 6, 2023

Could you rebase your commits, 14 commits for now...

@Override
public void handleMethodException(Class clazz, Method method, Object[] allArguments, Class<?>[] parameterTypes,
Throwable t) {
LOGGER.error("Failed to getDefault segment Id.", t);
Copy link
Member

Choose a reason for hiding this comment

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

What is default segment ID? Anything not default?


public abstract class WebFluxSkyWalkingStaticMethodsAroundInterceptor implements StaticMethodsAroundInterceptor {

protected static EnhancedInstance getInstance(Object o) {
Copy link
Member

Choose a reason for hiding this comment

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

As protected, why static?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

purpose was to serve as a internal-use static method

return instance;
}

protected static ContextSnapshot getContextSnapshot(Object o) {
Copy link
Member

Choose a reason for hiding this comment

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

Same here.

Comment on lines +59 to +60
// fetch trace ID
String traceId = WebFluxSkyWalkingTraceContext.traceId(exchange);
Copy link
Member

Choose a reason for hiding this comment

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

Please update all APIs you added. This is an official doc, we should provide a complete version.

@wuwen5
Copy link
Contributor

wuwen5 commented Jul 6, 2023

BTW , If the feature of apache/skywalking#10862 is implemented with minimal modifications, it seems that only the putCorrelation method needs to be implemented, as the current WebFluxSkyWalkingOperators + TraceContext can support read operations.

e.g.

public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        ServerHttpRequest buildRequest = exchange.getRequest()
                .mutate()
                .headers(httpHeaders -> WebFluxSkyWalkingOperators.continueTracing(exchange, () -> {
                    httpHeaders.add("x-trace-id", TraceContext.traceId());
                    httpHeaders.add("x-segment-id", TraceContext.segmentId());
                    httpHeaders.add("x-span-id", String.valueOf(TraceContext.spanId()));
                }))
                .build();
        return chain.filter(exchange.mutate().request(buildRequest).build());
    }

@wu-sheng
Copy link
Member

wu-sheng commented Jul 6, 2023

Good catch. @darknesstm Let's minimal the changes.

@darknesstm
Copy link
Contributor Author

BTW , If the feature of apache/skywalking#10862 is implemented with minimal modifications, it seems that only the putCorrelation method needs to be implemented, as the current WebFluxSkyWalkingOperators + TraceContext can support read operations.

e.g.

public Mono<Void> filter(ServerWebExchange exchange, GatewayFilterChain chain) {

        ServerHttpRequest buildRequest = exchange.getRequest()
                .mutate()
                .headers(httpHeaders -> WebFluxSkyWalkingOperators.continueTracing(exchange, () -> {
                    httpHeaders.add("x-trace-id", TraceContext.traceId());
                    httpHeaders.add("x-segment-id", TraceContext.segmentId());
                    httpHeaders.add("x-span-id", String.valueOf(TraceContext.spanId()));
                }))
                .build();
        return chain.filter(exchange.mutate().request(buildRequest).build());
    }

In this context WebFluxSkyWalkingOperators.continueTracing will add a meaningless LocalSpan

@wu-sheng
Copy link
Member

wu-sheng commented Jul 7, 2023

In this context WebFluxSkyWalkingOperators.continueTracing will add a meaningless LocalSpan

Make sense. You are correct. Keep what you have built. But please update others accordingly.

@darknesstm darknesstm force-pushed the feature/scg_filter branch from 8e121f7 to b6bb310 Compare July 7, 2023 16:26
@darknesstm darknesstm force-pushed the feature/scg_filter branch from b6bb310 to 51ba252 Compare July 7, 2023 16:31
@wu-sheng wu-sheng added this to the 9.0.0 milestone Jul 7, 2023
Copy link
Member

@wu-sheng wu-sheng left a comment

Choose a reason for hiding this comment

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

LGTM

@wu-sheng wu-sheng merged commit c9a6170 into apache:main Jul 7, 2023
@darknesstm darknesstm deleted the feature/scg_filter branch July 8, 2023 01:38
yangyulely pushed a commit to yangyulely/skywalking-java that referenced this pull request May 25, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

4 participants