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

Adds Micrometer Tracing Example #110

Merged
merged 1 commit into from
Feb 6, 2024
Merged

Conversation

codefromthecrypt
Copy link
Member

This is the exact same project as webflux5-sleuth, except for micrometer. As always, the style is intentionally like other projects here for easy maintenance, even if it isn't how start.spring.io would do it.

This is more glitchy that sleuth.. for example, the log correlation doesn't work, and some properties are missing. It is also rev-locked until the next release of micrometer. That said, it performs the basics, and is a good start!

Copy link
Member Author

@codefromthecrypt codefromthecrypt left a comment

Choose a reason for hiding this comment

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

notes

@@ -63,6 +63,10 @@ Here are the example projects you can try:
* Trace Instrumentation: [WebFlux Server](https://github.com/spring-cloud/spring-cloud-sleuth/blob/2.2.x/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/TraceWebFilter.java), [WebFlux Client](https://github.com/spring-cloud/spring-cloud-sleuth/blob/2.2.x/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/web/client/TraceWebClientBeanPostProcessor.java), [Reactor Context](https://github.com/spring-cloud/spring-cloud-sleuth/blob/2.2.x/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/instrument/reactor/ScopePassingSpanSubscriber.java), [SLF4J](https://github.com/openzipkin/brave/tree/master/context/slf4j)
* Trace Configuration: [Spring Cloud Sleuth](https://github.com/spring-cloud/spring-cloud-sleuth/tree/2.2.x/spring-cloud-sleuth-core/src/main/java/org/springframework/cloud/sleuth/autoconfig) [Properties](webflux5-sleuth/src/main/resources/application.properties)

* [webflux6-micrometer](webflux6-micrometer) `BRAVE_EXAMPLE=webflux6-micrometer docker-compose up`
* Runtime: Spring 6, Reactor Netty, Spring Boot 3, Micrometer, Log4J 2, JRE 21
* Trace Configuration: [Spring Boot Actuator](https://github.com/spring-projects/spring-boot/blob/3.2.x/spring-boot-project/spring-boot-actuator-autoconfigure/src/main/java/org/springframework/boot/actuate/autoconfigure/tracing/TracingProperties.java)
Copy link
Member Author

Choose a reason for hiding this comment

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

normally I add a 'Trace Instrumentation' section with links as you can see above, but this time, I have no idea where they are! Also, I don't see any canonical page on properties in docs, so I'm referencing the java type directly.

DOCKER_PARENT_IMAGE=ghcr.io/openzipkin/java:11.0.22_p7-jre
;;
17 )
DOCKER_BUILD_IMAGE=ghcr.io/openzipkin/java:21.0.2_p13
Copy link
Member Author

Choose a reason for hiding this comment

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

had to parameterize this as spring boot requires minimal JRE 17.. the first project to require this.

level:
root: INFO
pattern:
# Note: Logs don't appear to have any correlation fields assigned.
Copy link
Member Author

Choose a reason for hiding this comment

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

I hope log correlation isn't a w3c only thing.. I perused a bunch of github issues and seems people have been steered towards w3c, but I don't know if that's just because maintainers like it more, or if logic hasn't been stitched together to make normal brave work like before (even spring 2.5 can do this). @shakuzen if you know the scoop lemme know!

# Note: There is no property to bind ${brave.traceId128Bit:false}
span-joining-supported: ${brave.supportsJoin:true}
sampling:
# There doesn't seem to be a way to skip tracing /health by property
Copy link
Member Author

Choose a reason for hiding this comment

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

I'm probably missing something as it seems like no one would want to trace /health by default, and especially not have a way to disable it..

Screenshot 2024-02-06 at 20 50 56

@codefromthecrypt
Copy link
Member Author

For the curious, the data collected is a lot more chatty as it doesn't use brave's http data collection policy. So, basically the bridge isn't going to be able to conform data like native brave does, and avoid things like empty tags for "not exception" etc, or basically use any of the brave tagging functions.

Screenshot 2024-02-06 at 20 52 56
curl -s localhost:9411/api/v2/trace/65c2398c3dd7d31bdb073f203574eff6|jq .
[
  {
    "traceId": "65c2398c3dd7d31bdb073f203574eff6",
    "parentId": "db073f203574eff6",
    "id": "004c6b75a8173964",
    "kind": "CLIENT",
    "name": "http get",
    "timestamp": 1707227532574300,
    "duration": 125911,
    "localEndpoint": {
      "serviceName": "frontend",
      "ipv4": "192.168.106.1"
    },
    "tags": {
      "client.name": "127.0.0.1",
      "exception": "none",
      "http.url": "http://127.0.0.1:9000/api",
      "method": "GET",
      "outcome": "SUCCESS",
      "status": "200",
      "uri": "/api"
    }
  },
  {
    "traceId": "65c2398c3dd7d31bdb073f203574eff6",
    "id": "db073f203574eff6",
    "kind": "SERVER",
    "name": "http get /",
    "timestamp": 1707227532559293,
    "duration": 143467,
    "localEndpoint": {
      "serviceName": "frontend",
      "ipv4": "192.168.106.1"
    },
    "tags": {
      "exception": "none",
      "http.url": "/",
      "method": "GET",
      "outcome": "SUCCESS",
      "status": "200",
      "uri": "/"
    }
  },
  {
    "traceId": "65c2398c3dd7d31bdb073f203574eff6",
    "parentId": "004c6b75a8173964",
    "id": "a6c2578318da548d",
    "kind": "SERVER",
    "name": "http get /api",
    "timestamp": 1707227532672168,
    "duration": 24146,
    "localEndpoint": {
      "serviceName": "backend",
      "ipv4": "192.168.106.1"
    },
    "tags": {
      "exception": "none",
      "http.url": "/api",
      "method": "GET",
      "outcome": "SUCCESS",
      "status": "200",
      "uri": "/api"
    }
  }
]

@codefromthecrypt
Copy link
Member Author

codefromthecrypt commented Feb 6, 2024

Here's an example of the canonical brave trace, using the armeria example. Armeria adds more timing annotations, but the tags are standard and can be modified uniformly as necessary, like all the others, with brave's HttpTracing type:

Screenshot 2024-02-06 at 21 01 42
$ curl -s localhost:9411/api/v2/trace/ca91e1a961286b00|jq .
[
  {
    "traceId": "ca91e1a961286b00",
    "parentId": "32ca56351b2e40ed",
    "id": "66bf704f516a5e6b",
    "kind": "SERVER",
    "name": "get /api",
    "timestamp": 1707228075240926,
    "duration": 3438,
    "localEndpoint": {
      "serviceName": "backend",
      "ipv4": "192.168.106.1"
    },
    "remoteEndpoint": {
      "ipv4": "127.0.0.1",
      "port": 60553
    },
    "annotations": [
      {
        "timestamp": 1707228075241119,
        "value": "wr"
      },
      {
        "timestamp": 1707228075243588,
        "value": "ws"
      }
    ],
    "tags": {
      "http.method": "GET",
      "http.path": "/api"
    }
  },
  {
    "traceId": "ca91e1a961286b00",
    "parentId": "ca91e1a961286b00",
    "id": "32ca56351b2e40ed",
    "kind": "CLIENT",
    "name": "get",
    "timestamp": 1707228075236792,
    "duration": 7889,
    "localEndpoint": {
      "serviceName": "frontend",
      "ipv4": "192.168.106.1"
    },
    "remoteEndpoint": {
      "serviceName": "backend",
      "ipv4": "127.0.0.1",
      "port": 9000
    },
    "annotations": [
      {
        "timestamp": 1707228075241134,
        "value": "ws"
      },
      {
        "timestamp": 1707228075244181,
        "value": "wr"
      }
    ],
    "tags": {
      "http.method": "GET",
      "http.path": "/api"
    }
  },
  {
    "traceId": "ca91e1a961286b00",
    "id": "ca91e1a961286b00",
    "kind": "SERVER",
    "name": "get /",
    "timestamp": 1707228075236174,
    "duration": 9511,
    "localEndpoint": {
      "serviceName": "frontend",
      "ipv4": "192.168.106.1"
    },
    "annotations": [
      {
        "timestamp": 1707228075236255,
        "value": "wr"
      },
      {
        "timestamp": 1707228075245259,
        "value": "ws"
      }
    ],
    "tags": {
      "http.method": "GET",
      "http.path": "/"
    }
  }
]

@codefromthecrypt
Copy link
Member Author

Thanks for the look @anuraaga!

@shakuzen any notes you may have you can either tell me or raise a PR. We need to bump this soon anyway on the next micrometer release to unlock the brave version.

@codefromthecrypt codefromthecrypt merged commit d14a9b4 into master Feb 6, 2024
10 checks passed
@codefromthecrypt codefromthecrypt deleted the micrometer-example branch February 6, 2024 14:05
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.

2 participants