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

feat: add OpenTelemetry feature into Gravitee Node #374

Draft
wants to merge 1 commit into
base: alpha
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
19 changes: 13 additions & 6 deletions gravitee-node-api/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@
<parent>
<groupId>io.gravitee.node</groupId>
<artifactId>gravitee-node</artifactId>
<version>6.5.0</version>
<version>7.0.0-archi-401-opentelemetry-SNAPSHOT</version>
</parent>

<artifactId>gravitee-node-api</artifactId>
Expand All @@ -48,11 +48,6 @@
<artifactId>gravitee-reporter-api</artifactId>
</dependency>

<dependency>
<groupId>io.gravitee.tracing</groupId>
<artifactId>gravitee-tracing-api</artifactId>
</dependency>

<!-- RxJava 3 -->
<dependency>
<groupId>io.reactivex.rxjava3</groupId>
Expand All @@ -63,5 +58,17 @@
<groupId>com.google.guava</groupId>
<artifactId>guava</artifactId>
</dependency>

<!-- Vertx -->
<dependency>
<groupId>io.vertx</groupId>
<artifactId>vertx-core</artifactId>
</dependency>

<!-- OpenTelemetry -->
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
</dependencies>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.api.opentelemetry;

import io.vertx.core.Context;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public interface InstrumenterTracer {
String instrumentationName();

<R> boolean canHandle(final R request);

<R> Span startSpan(final Context vertxContext, final R request, final boolean root, final Span parentSpan);

<R> void endSpan(final Context vertxContext, final Span span, final R response, final Throwable throwable);
}
Original file line number Diff line number Diff line change
@@ -1,27 +1,26 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.api.tracing;
package io.gravitee.node.api.opentelemetry;

import io.gravitee.common.component.LifecycleComponent;
import io.gravitee.tracing.api.Span;
import io.opentelemetry.api.OpenTelemetry;

/**
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public interface Tracer extends LifecycleComponent<Tracer> {
Span trace(String spanName);
public interface InstrumenterTracerFactory {
InstrumenterTracer createInstrumenterTracer(final OpenTelemetry openTelemetry);
}
Original file line number Diff line number Diff line change
@@ -1,26 +1,26 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.tracing.plugin;

import io.gravitee.plugin.core.api.Plugin;
package io.gravitee.node.api.opentelemetry;

/**
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public interface TracerPlugin extends Plugin {
String PLUGIN_TYPE = "tracer";
public interface Span {
boolean isRoot();

<T> Span withAttribute(final String name, final T value);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,43 @@
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.api.opentelemetry;

import io.gravitee.common.service.Service;
import io.vertx.core.Context;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public interface Tracer extends Service<Tracer> {
<R> Span startRootSpanFrom(final Context vertxContext, final R request);

<R> Span startSpanFrom(final Context vertxContext, final R request);

<R> Span startSpanWithParentFrom(Context vertxContext, Span parentSpan, R request);

void end(final Context vertxContext, final Span span);

void endOnError(final Context vertxContext, final Span span, final Throwable throwable);

void endOnError(final Context vertxContext, final Span span, final String message);

<R> void endWithResponse(final Context vertxContext, final Span span, final R response);

<R> void endWithResponseAndError(final Context vertxContext, final Span span, final R response, final Throwable throwable);

<R> void endWithResponseAndError(final Context vertxContext, final Span span, final R response, final String message);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.api.opentelemetry;

import java.util.List;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public interface TracerFactory {
Tracer createTracer(
final String id,
final String serviceName,
final String serviceNamespace,
final String version,
final List<InstrumenterTracerFactory> instrumenterTracerFactories
);
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,106 @@
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.api.opentelemetry.http;

import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpClientRequest;
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.RequestOptions;
import io.vertx.core.http.impl.HttpRequestHead;
import io.vertx.core.http.impl.headers.HeadersMultiMap;
import io.vertx.core.net.SocketAddress;
import lombok.AllArgsConstructor;
import lombok.Getter;
import lombok.NonNull;
import lombok.RequiredArgsConstructor;
import lombok.Setter;
import lombok.experimental.Accessors;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
@RequiredArgsConstructor
@Getter
@Setter
@Accessors(fluent = true)
public class ObservableHttpClientRequest implements ObservableHttpRequest {

@NonNull
private final RequestOptions requestOptions;

private HttpClientRequest httpClientRequest;

/**
* Only used for internal Vertx testing; see {@link HttpRequestHead#id() }
*/
@Override
public int id() {
return 0;
}

@Override
public String uri() {
return requestOptions.getURI();
}

@Override
public String absoluteURI() {
return (
(Boolean.TRUE.equals(requestOptions.isSsl()) ? "https://" : "http://") +
requestOptions.getHost() +
':' +
requestOptions.getPort() +
requestOptions.getURI()
);
}

@Override
public HttpMethod method() {
return requestOptions.getMethod();
}

@Override
public MultiMap headers() {
MultiMap headers = null;
if (httpClientRequest != null) {
headers = httpClientRequest.headers();
}
if (headers == null) {
headers = requestOptions.getHeaders();
}
if (headers == null) {
return HeadersMultiMap.headers();
}
return headers;
}

@Override
public SocketAddress remoteAddress() {
return requestOptions.getServer();
}

public String traceOperation() {
String traceOperation = null;
if (httpClientRequest != null) {
traceOperation = httpClientRequest.traceOperation();
}
if (traceOperation == null) {
traceOperation = requestOptions.getTraceOperation();
}
return traceOperation;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.api.opentelemetry.http;

import io.vertx.core.MultiMap;
import io.vertx.core.http.HttpClientResponse;
import io.vertx.core.spi.observability.HttpResponse;

/**
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public record ObservableHttpClientResponse(HttpClientResponse httpClientResponse) implements ObservableHttpResponse {
@Override
public int statusCode() {
return httpClientResponse.statusCode();
}

@Override
public MultiMap headers() {
return httpClientResponse.headers();
}
}
Original file line number Diff line number Diff line change
@@ -1,24 +1,24 @@
/**
* Copyright (C) 2015 The Gravitee team (http://gravitee.io)
/*
* Copyright © 2015 The Gravitee team (http://gravitee.io)
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software
* distributed under the License is distributed on an "AS IS" BASIS,
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
* See the License for the specific language governing permissions and
* limitations under the License.
*/
package io.gravitee.node.tracing.vertx;
package io.gravitee.node.api.opentelemetry.http;

import io.gravitee.node.api.tracing.Tracer;
import io.vertx.core.spi.observability.HttpRequest;

/**
* @author David BRASSELY (david.brassely at graviteesource.com)
* @author Guillaume LAMIRAND (guillaume.lamirand at graviteesource.com)
* @author GraviteeSource Team
*/
public interface VertxTracer<I, O> extends Tracer, io.vertx.core.spi.tracing.VertxTracer<I, O> {}
public interface ObservableHttpRequest extends HttpRequest {}
Loading