Skip to content

Commit

Permalink
Intellij cleanup of markdown and yaml (#3284)
Browse files Browse the repository at this point in the history
* Intellij cleanup of markdown and yaml

* Revert required yaml param
  • Loading branch information
trask authored Jun 14, 2021
1 parent 8be1006 commit f1beb23
Show file tree
Hide file tree
Showing 10 changed files with 82 additions and 81 deletions.
3 changes: 2 additions & 1 deletion .github/workflows/build-grpc-smoke-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
paths:
- 'smoke-tests/grpc/**'
- '.github/workflows/build-grpc-smoke-dist.yml'
branches: 'main'
branches:
- main
workflow_dispatch:

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-play-smoke-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
paths:
- 'smoke-tests/play/**'
- '.github/workflows/build-play-smoke-dist.yml'
branches: 'main'
branches:
- main
workflow_dispatch:

jobs:
Expand Down
3 changes: 2 additions & 1 deletion .github/workflows/build-springboot-smoke-dist.yml
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,8 @@ on:
paths:
- 'smoke-tests/springboot/**'
- '.github/workflows/build-springboot-smoke-dist.yml'
branches: 'main'
branches:
- main
workflow_dispatch:

jobs:
Expand Down
1 change: 1 addition & 0 deletions .github/workflows/patch-release-build.yml
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ on:
required: true
commits:
description: Comma separated list of commit shas to cherrypick
required: false

jobs:
prepare-release-branch:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -102,7 +102,7 @@ behavior you find.*

## Supported libraries, frameworks, and application servers

We support an impressively huge number of [libraries and frameworks](docs/supported-libraries.md#libraries---frameworks) and
We support an impressively huge number of [libraries and frameworks](docs/supported-libraries.md#libraries--frameworks) and
a majority of the most popular [application servers](docs/supported-libraries.md#application-servers)...right out of the box!
[Click here to see the full list](docs/supported-libraries.md) and to learn more about
[disabled instrumentation](docs/supported-libraries.md#disabled-instrumentations)
Expand Down
4 changes: 2 additions & 2 deletions docs/manual-instrumentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@ or they might want to manually create spans for their own custom code.
* [Maven](#maven)
* [Gradle](#gradle)
- [Adding attributes to the current span](#adding-attributes-to-the-current-span)
- [Creating spans around methods with `@WithSpan`](#creating-spans-around-methods-with---withspan-)
* [Suppressing `@WithSpan` instrumentation](#suppressing---withspan--instrumentation)
- [Creating spans around methods with `@WithSpan`](#creating-spans-around-methods-with-withspan)
* [Suppressing `@WithSpan` instrumentation](#suppressing-withspan-instrumentation)
* [Creating spans around methods with `otel.instrumentation.methods.include`](#creating-spans-around-methods-with-otelinstrumentationmethodsinclude)
- [Creating spans manually with a Tracer](#creating-spans-manually-with-a-tracer)

Expand Down
2 changes: 1 addition & 1 deletion docs/supported-libraries.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ or [contributing](../CONTRIBUTING.md).

## Contents

* [Libraries / Frameworks](#libraries---frameworks)
* [Libraries / Frameworks](#libraries--frameworks)
* [Application Servers](#application-servers)
* [JVMs and Operating Systems](#jvms-and-operating-systems)
* [Disabled instrumentations](#disabled-instrumentations)
Expand Down
2 changes: 1 addition & 1 deletion examples/extension/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -62,7 +62,7 @@ Write a _new_ instrumentation which injects its own advice into the same method
Use `order` method to ensure it is run after the original instrumentation.
Now you can augment current span with new information.

See [DemoServlet3InstrumentationModule](instrumentation/servlet-3/src/main/java/com/example/javaagent/instrumentation/DemoServlet3InstrumentationModule.java).
See [DemoServlet3InstrumentationModule](src/main/java/com/example/javaagent/instrumentation/DemoServlet3InstrumentationModule.java).

### I want to remove some attributes
Write custom exporter or use attribute filtering functionality in Collector.
Expand Down
133 changes: 65 additions & 68 deletions instrumentation/spring/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@ The [first section](#manual-instrumentation-with-java-sdk) will walk you through

The [second section](#manual-instrumentation-using-handlers-and-filters) will build on the first. It will walk you through implementing spring-web handler and filter interfaces to create traces with minimal changes to existing application code. Using the OpenTelemetry API, this approach involves copy and pasting files and a significant amount of manual configurations.

The [third section](#auto-instrumentation-using-spring-starters) with build on the first two sections. We will use spring auto-configurations and instrumentation tools packaged in OpenTelemetry [Spring Starters](starters/) to streamline the set up of OpenTelemetry using Spring. With these tools you will be able to setup distributed tracing with little to no changes to existing configurations and easily customize traces with minor additions to application code.
The [third section](#auto-instrumentation-using-spring-starters) with build on the first two sections. We will use spring auto-configurations and instrumentation tools packaged in OpenTelemetry [Spring Starters](starters) to streamline the set up of OpenTelemetry using Spring. With these tools you will be able to setup distributed tracing with little to no changes to existing configurations and easily customize traces with minor additions to application code.

In this guide we will be using a running example. In section one and two, we will create two spring web services using Spring Boot. We will then trace requests between these services using two different approaches. Finally, in section three we will explore tools documented in [opentelemetry-spring-boot-autoconfigure](/spring-boot-autoconfigure/README.md#features) which can improve this process.

Expand Down Expand Up @@ -107,7 +107,7 @@ import io.opentelemetry.exporters.logging.*;
public class OtelConfig {
private static final String tracerName = "fooTracer";
@Bean
public Tracer otelTracer() throws Exception {
public Tracer otelTracer() {
Tracer tracer = OpenTelemetry.getGlobalTracer(tracerName);

SpanProcessor logProcessor = SimpleSpanProcessor.newBuilder(new LoggingSpanExporter()).build();
Expand Down Expand Up @@ -155,7 +155,7 @@ Required dependencies and configurations for MainService and TimeService project
@SpringBootApplication
public class MainServiceApplication {

public static void main(String[] args) throws IOException {
public static void main(String[] args) {
SpringApplication.run(MainServiceApplication.class, args);
}
}
Expand Down Expand Up @@ -211,7 +211,6 @@ public class MainServiceController {

HttpUtils is a helper class that injects the current span context into outgoing requests. This involves adding the tracer id and the trace-state to a request header. For this example, we used `RestTemplate` to send requests from `MainService` to `TimeService`. A similar approach can be used with popular Java Web Clients such as [okhttp](https://square.github.io/okhttp/) and [apache http client](https://www.tutorialspoint.com/apache_httpclient/apache_httpclient_quick_guide.htm). The key to this implementation is to override the put method in `TextMapPropagator.Setter<?>` to handle your request format. `TextMapPropagator.inject` will use this setter to set `traceparent` and `tracestate` headers in your requests. These values will be used to propagate your span context to external services.


```java
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.HttpEntity;
Expand All @@ -231,35 +230,35 @@ import io.opentelemetry.api.trace.Tracer;
@Component
public class HttpUtils {

private static final TextMapPropagator.Setter<HttpHeaders> setter = new TextMapPropagator.Setter<HttpHeaders>() {
@Override
public void set(HttpHeaders headers, String key, String value) {
headers.set(key, value);
}
};
private static final TextMapPropagator.Setter<HttpHeaders> setter = new TextMapPropagator.Setter<HttpHeaders>() {
@Override
public void set(HttpHeaders headers, String key, String value) {
headers.set(key, value);
}
};

@Autowired
private Tracer tracer;
@Autowired
private Tracer tracer;

private TextMapPropagator<SpanContext> textFormat;
private final TextMapPropagator<SpanContext> textFormat;

public HttpUtils(Tracer tracer) {
textFormat = tracer.getTextMapPropagator();
}
public HttpUtils(Tracer tracer) {
textFormat = tracer.getTextMapPropagator();
}

public String callEndpoint(String url) throws Exception {
HttpHeaders headers = new HttpHeaders();
public String callEndpoint(String url) {
HttpHeaders headers = new HttpHeaders();

textFormat.inject(Context.current(), headers, setter);
textFormat.inject(Context.current(), headers, setter);

HttpEntity<String> entity = new HttpEntity<String>(headers);
RestTemplate restTemplate = new RestTemplate();
HttpEntity<String> entity = new HttpEntity<String>(headers);
RestTemplate restTemplate = new RestTemplate();

ResponseEntity<String> response =
restTemplate.exchange(url, HttpMethod.GET, entity, String.class);
ResponseEntity<String> response =
restTemplate.exchange(url, HttpMethod.GET, entity, String.class);

return response.getBody();
}
return response.getBody();
}
}
```
### Instrumentation of TimeService
Expand All @@ -277,7 +276,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TimeServiceApplication {

public static void main(String[] args) throws IOException {
public static void main(String[] args) {
SpringApplication.run(TimeServiceApplication.class, args);
}
}
Expand Down Expand Up @@ -358,7 +357,7 @@ import org.springframework.boot.autoconfigure.SpringBootApplication;
@SpringBootApplication
public class TimeServiceApplication {

public static void main(String[] args) throws IOException {
public static void main(String[] args) {
SpringApplication.run(TimeServiceApplication.class, args);
}
}
Expand Down Expand Up @@ -408,8 +407,7 @@ public class ControllerFilter implements Filter {
};

@Override
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) {
LOG.info("start doFilter");

HttpServletRequest req = (HttpServletRequest) request;
Expand Down Expand Up @@ -444,7 +442,7 @@ Ensure the main method in MainServiceApplication is defined. This will be the en
@SpringBootApplication
public class MainServiceApplication {

public static void main(String[] args) throws IOException {
public static void main(String[] args) {
SpringApplication.run(MainServiceApplication.class, args);
}
}
Expand Down Expand Up @@ -499,7 +497,6 @@ To propagate the span context from MainService to TimeService we must inject the

Include the two classes below to your MainService project to add this functionality:


```java

import java.io.IOException;
Expand All @@ -520,35 +517,35 @@ import io.opentelemetry.api.trace.Tracer;
@Component
public class RestTemplateInterceptor implements ClientHttpRequestInterceptor {

@Autowired
private Tracer tracer;
@Autowired
private Tracer tracer;

private static final TextMapPropagator.Setter<HttpRequest> setter =
new TextMapPropagator.Setter<HttpRequest>() {
@Override
public void set(HttpRequest carrier, String key, String value) {
carrier.getHeaders().set(key, value);
}
};
private static final TextMapPropagator.Setter<HttpRequest> setter =
new TextMapPropagator.Setter<HttpRequest>() {
@Override
public void set(HttpRequest carrier, String key, String value) {
carrier.getHeaders().set(key, value);
}
};


@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) throws IOException {
@Override
public ClientHttpResponse intercept(HttpRequest request, byte[] body,
ClientHttpRequestExecution execution) {

String spanName = request.getMethodValue() + " " + request.getURI().toString();
Span currentSpan = tracer.spanBuilder(spanName).setSpanKind(SpanKind.CLIENT).startSpan();
String spanName = request.getMethodValue() + " " + request.getURI().toString();
Span currentSpan = tracer.spanBuilder(spanName).setSpanKind(SpanKind.CLIENT).startSpan();

try (Scope scope = tracer.withSpan(currentSpan)) {
OpenTelemetry.getPropagators().getTextMapPropagator().inject(Context.current(), request, setter);
ClientHttpResponse response = execution.execute(request, body);
LOG.info(String.format("Request sent from RestTemplateInterceptor"));
try (Scope scope = tracer.withSpan(currentSpan)) {
OpenTelemetry.getPropagators().getTextMapPropagator().inject(Context.current(), request, setter);
ClientHttpResponse response = execution.execute(request, body);
LOG.info("Request sent from RestTemplateInterceptor");

return response;
}finally {
currentSpan.end();
}
}
return response;
} finally {
currentSpan.end();
}
}
}

```
Expand Down Expand Up @@ -642,26 +639,26 @@ import org.springframework.web.client.RestTemplate;
@SpringBootApplication
public class MainServiceApplication {

public static void main(String[] args) throws IOException {
public static void main(String[] args) {
SpringApplication.run(MainServiceApplication.class, args);
}

@RestController
@RequestMapping(value = "/message")
public class MainServiceController {
private static final String TIME_SERVICE_URL = "http://localhost:8080/time";

@Autowired
private RestTemplate restTemplate;
public static class MainServiceController {
private static final String TIME_SERVICE_URL = "http://localhost:8080/time";

@Autowired
private RestTemplate restTemplate;

@GetMapping
public String message() {
return restTemplate.exchange(TIME_SERVICE_URL, HttpMethod.GET, null, String.class).getBody();
}

@GetMapping
public String message() {
return restTemplate.exchange(TIME_SERVICE_URL, HttpMethod.GET, null, String.class).getBody();
}

@Bean
public RestTemplate restTemplate() {
return new RestTemplate();
return new RestTemplate();
}
}
}
Expand Down Expand Up @@ -714,7 +711,7 @@ import io.opentelemetry.api.trace.Tracer;
@SpringBootApplication
public class TimeServiceApplication {

public static void main(String[] args) throws IOException {
public static void main(String[] args) {
SpringApplication.run(TimeServiceApplication.class, args);
}

Expand Down
Loading

0 comments on commit f1beb23

Please sign in to comment.