Skip to content

Commit

Permalink
add RayId to HttpServer span (#928)
Browse files Browse the repository at this point in the history
* add RayId to HttpServer span when there is Cloudflare RayId header but no timestamp headers.

* update tracing document.
  • Loading branch information
LokiWager committed Feb 13, 2023
1 parent eec7d77 commit 37714a6
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 10 deletions.
21 changes: 11 additions & 10 deletions doc/cookbook/distributed-tracing.md
Original file line number Diff line number Diff line change
Expand Up @@ -116,17 +116,18 @@ rules:

## Usage with Cloudflare

1. Add headers for the timestamps when the traffic enters Cloudflare.
1. Go to your website in Cloudflare dashboard.
2. Go to Rules -> Transform Rules -> Modify Request Header then create a rule
3. Add two dynamic headers:
- "x-ts-msec":"http.request.timestamp.msec"
- "x-ts-sec":"http.request.timestamp.sec"
If a request comes from Cloudflare, the HttpServer span will have a `cf.ray` tag with the value of the Cloudflare RayID automatically.

![cloudflare-transform-rule-header](../imgs/tracing-cloudflare-transform-header.png)
You can also have a Cloudflare span over the HttpServer span.

2. No need to change any Easegress configuration
![cloudflare-span](../imgs/tracing-cloudflare-span.png)

3. On your tracing UI, you'll find a span called `cloudflare`. This span has a tag called `cf.ray` whose value is a Cloudflare Ray ID. You can use Ray ID for further troubleshooting on Cloudflare.
To achieve that you need to add headers of the timestamps when the traffic enters Cloudflare.

![cloudflare-span](../imgs/tracing-cloudflare-span.png)
1. Go to your website in Cloudflare dashboard.
2. Go to Rules -> Transform Rules -> Modify Request Header then create a rule.
3. Add two dynamic headers:
- "x-ts-msec":"http.request.timestamp.msec"
- "x-ts-sec":"http.request.timestamp.sec"

![cloudflare-transform-rule-header](../imgs/tracing-cloudflare-transform-header.png)
1 change: 1 addition & 0 deletions pkg/tracing/cloudflare.go
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,7 @@ func newSpanForCloudflare(ctx context.Context, t *Tracer, spanName string, req *
defer func() {
if span == nil {
span = t.newSpanWithStart(ctx, spanName, fasttime.Now())
span.SetAttributes(attribute.String("cf.ray", rayID))
}
}()

Expand Down

0 comments on commit 37714a6

Please sign in to comment.