Skip to content
Merged
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
2 changes: 2 additions & 0 deletions apache-camel/src/main/descriptors/common-bin.xml
Original file line number Diff line number Diff line change
Expand Up @@ -284,6 +284,7 @@
<include>org.apache.camel:camel-olingo4-api</include>
<include>org.apache.camel:camel-openapi-java</include>
<include>org.apache.camel:camel-openstack</include>
<include>org.apache.camel:camel-opentelemetry</include>
<include>org.apache.camel:camel-opentracing</include>
<include>org.apache.camel:camel-optaplanner</include>
<include>org.apache.camel:camel-paho</include>
Expand Down Expand Up @@ -370,6 +371,7 @@
<include>org.apache.camel:camel-thrift</include>
<include>org.apache.camel:camel-tika</include>
<include>org.apache.camel:camel-timer</include>
<include>org.apache.camel:camel-tracing</include>
<include>org.apache.camel:camel-twilio</include>
<include>org.apache.camel:camel-twitter</include>
<include>org.apache.camel:camel-undertow</include>
Expand Down
10 changes: 10 additions & 0 deletions bom/camel-bom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -1343,6 +1343,11 @@
<artifactId>camel-openstack</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-opentelemetry</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-opentracing</artifactId>
Expand Down Expand Up @@ -1813,6 +1818,11 @@
<artifactId>camel-tooling-util</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-tracing</artifactId>
<version>${project.version}</version>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-twilio</artifactId>
Expand Down
1 change: 1 addition & 0 deletions camel-dependencies/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -459,6 +459,7 @@
<olingo4-version>4.7.1</olingo4-version>
<openjpa-version>3.1.2</openjpa-version>
<openstack4j-version>3.0.2</openstack4j-version>
<opentelemetry-version>0.6.0</opentelemetry-version>
<opentracing-tracerresolver-version>0.1.8</opentracing-tracerresolver-version>
<opentracing-version>0.33.0</opentracing-version>
<openwebbeans-version>1.7.3</openwebbeans-version>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"other": {
"kind": "other",
"name": "opentelemetry",
"title": "OpenTelemetry",
"description": "Distributed tracing using OpenTelemetry",
"deprecated": false,
"firstVersion": "3.5.0",
"label": "monitoring,microservice",
"supportLevel": "Preview",
"groupId": "org.apache.camel",
"artifactId": "camel-opentelemetry",
"version": "3.5.0-SNAPSHOT"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
{
"other": {
"kind": "other",
"name": "tracing",
"title": "Tracing",
"description": "Distributed tracing common interfaces",
"deprecated": false,
"firstVersion": "3.5.0",
"supportLevel": "Preview",
"groupId": "org.apache.camel",
"artifactId": "camel-tracing",
"version": "3.5.0-SNAPSHOT"
}
}
89 changes: 89 additions & 0 deletions components/camel-opentelemetry/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
<?xml version="1.0" encoding="UTF-8"?>
<!--

Licensed to the Apache Software Foundation (ASF) under one or more
contributor license agreements. See the NOTICE file distributed with
this work for additional information regarding copyright ownership.
The ASF licenses this file to You 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.

-->
<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/xsd/maven-4.0.0.xsd">
<modelVersion>4.0.0</modelVersion>

<parent>
<groupId>org.apache.camel</groupId>
<artifactId>components</artifactId>
<version>3.5.0-SNAPSHOT</version>
</parent>


<artifactId>camel-opentelemetry</artifactId>
<packaging>jar</packaging>
<name>Camel :: OpenTelemetry</name>
<description>Distributed tracing using OpenTelemetry</description>

<properties>
<firstVersion>3.5.0</firstVersion>
<label>monitoring,microservice</label>
<title>OpenTelemetry</title>
<opentracing-agent.lib>${project.build.directory}/lib</opentracing-agent.lib>
</properties>

<dependencies>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-support</artifactId>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-tracing</artifactId>
</dependency>
<dependency>
<groupId>io.grpc</groupId>
<artifactId>grpc-netty-shaded</artifactId>
<version>${grpc-version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
<version>${opentelemetry-version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
<version>${opentelemetry-version}</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporters-otlp</artifactId>
<version>${opentelemetry-version}</version>
</dependency>
<dependency>
<groupId>org.apache.logging.log4j</groupId>
<artifactId>log4j-slf4j-impl</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.apache.camel</groupId>
<artifactId>camel-test-spring-junit5</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporters-inmemory</artifactId>
<version>${opentelemetry-version}</version>
</dependency>

</dependencies>

</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,7 @@
# Generated by camel build tools - do NOT edit this file!
name=opentelemetry
groupId=org.apache.camel
artifactId=camel-opentelemetry
version=3.5.0-SNAPSHOT
projectName=Camel :: OpenTelemetry
projectDescription=Distributed tracing using OpenTelemetry
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
{
"other": {
"kind": "other",
"name": "opentelemetry",
"title": "OpenTelemetry",
"description": "Distributed tracing using OpenTelemetry",
"deprecated": false,
"firstVersion": "3.5.0",
"label": "monitoring,microservice",
"supportLevel": "Preview",
"groupId": "org.apache.camel",
"artifactId": "camel-opentelemetry",
"version": "3.5.0-SNAPSHOT"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,120 @@
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF licenses this file to You 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 org.apache.camel.opentelemetry;

import java.util.EnumMap;
import java.util.Map;

import io.opentelemetry.common.AttributeValue;
import io.opentelemetry.common.Attributes;
import io.opentelemetry.trace.attributes.SemanticAttributes;
import org.apache.camel.tracing.SpanAdapter;
import org.apache.camel.tracing.Tag;

public class OpenTelemetrySpanAdapter implements SpanAdapter {
private static final String DEFAULT_EVENT_NAME = "log";

private static EnumMap<Tag, String> tagMap = new EnumMap<>(Tag.class);

static {
tagMap.put(Tag.COMPONENT, "component");
tagMap.put(Tag.DB_TYPE, SemanticAttributes.DB_TYPE.key());
tagMap.put(Tag.DB_STATEMENT, SemanticAttributes.DB_STATEMENT.key());
tagMap.put(Tag.DB_INSTANCE, SemanticAttributes.DB_INSTANCE.key());
tagMap.put(Tag.HTTP_METHOD, SemanticAttributes.HTTP_METHOD.key());
tagMap.put(Tag.HTTP_STATUS, SemanticAttributes.HTTP_STATUS_CODE.key());
tagMap.put(Tag.HTTP_URL, SemanticAttributes.HTTP_URL.key());
tagMap.put(Tag.MESSAGE_BUS_DESTINATION, "message_bus.destination");
}


io.opentelemetry.trace.Span span;

OpenTelemetrySpanAdapter(io.opentelemetry.trace.Span span) {
this.span = span;
}

io.opentelemetry.trace.Span getOpenTelemetrySpan() {
return this.span;
}

@Override public void setComponent(String component) {
this.span.setAttribute("component", component);
}

@Override public void setError(boolean error) {
this.span.setAttribute("error", error);
}

@Override public void setTag(Tag key, String value) {
this.span.setAttribute(tagMap.get(key), value);
}

@Override public void setTag(Tag key, Number value) {
this.span.setAttribute(tagMap.get(key), value.intValue());
}

@Override public void setTag(String key, String value) {
this.span.setAttribute(key, value);
}

@Override public void setTag(String key, Number value) {
this.span.setAttribute(key, value.intValue());
}

@Override public void setTag(String key, Boolean value) {
this.span.setAttribute(key, value);
}

@Override public void log(Map<String, String> fields) {
span.addEvent(getEventNameFromFields(fields), convertToAttributes(fields));
}

String getEventNameFromFields(Map<String, ?> fields) {
Object eventValue = fields == null ? null : fields.get("event");
if (eventValue != null) {
return eventValue.toString();
}

return DEFAULT_EVENT_NAME;
}

Attributes convertToAttributes(Map<String, ?> fields) {
Attributes.Builder attributesBuilder = Attributes.newBuilder();

for (Map.Entry<String, ?> entry : fields.entrySet()) {
String key = entry.getKey();
Object value = entry.getValue();
if (value == null) {
continue;
}
if (value instanceof Byte
|| value instanceof Short
|| value instanceof Integer
|| value instanceof Long) {
attributesBuilder.setAttribute(key, AttributeValue.longAttributeValue(((Number) value).longValue()));
} else if (value instanceof Float || value instanceof Double) {
attributesBuilder.setAttribute(key, AttributeValue.doubleAttributeValue(((Number) value).doubleValue()));
} else if (value instanceof Boolean) {
attributesBuilder.setAttribute(key, AttributeValue.booleanAttributeValue((Boolean) value));
} else {
attributesBuilder.setAttribute(key, AttributeValue.stringAttributeValue(value.toString()));
}
}
return attributesBuilder.build();
}
}
Loading