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
63 changes: 63 additions & 0 deletions gxobservability/pom.xml
Original file line number Diff line number Diff line change
@@ -0,0 +1,63 @@
<?xml version="1.0" encoding="UTF-8"?>
<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>com.genexus</groupId>
<artifactId>parent</artifactId>
<version>${revision}${changelist}</version>
</parent>

<artifactId>gxobservability</artifactId>
<name>GeneXus Observability</name>

<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-api</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-trace</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-exporter-otlp</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-semconv</artifactId>
<version>1.30.1-alpha</version>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-extension-annotations</artifactId>
</dependency>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-sdk-extension-autoconfigure</artifactId>
<version>1.36.0</version>
</dependency>
</dependencies>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>io.opentelemetry</groupId>
<artifactId>opentelemetry-bom</artifactId>
<version>1.23.0</version>

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Can we bump to version 1.36?

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

Bumped to the latest.

<type>pom</type>
<scope>import</scope>
</dependency>
</dependencies>
</dependencyManagement>

<build>
<finalName>gxobservability</finalName>
</build>
</project>
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
package com.genexus.opentelemetry;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Context;
public class GXSpanContext
{
private io.opentelemetry.api.trace.SpanContext _spanContext;

public io.opentelemetry.api.trace.SpanContext getSpanContext()
{
return _spanContext;
}
public GXSpanContext(io.opentelemetry.api.trace.SpanContext spanContext)
{
this._spanContext = spanContext;
}
public GXSpanContext()
{
_spanContext = Span.current().getSpanContext();
}
public String traceId()
{
return _spanContext.getTraceId();
}
public String spanId()
{
return _spanContext.getSpanId();
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.genexus.opentelemetry;

import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Context;

public class GXTraceContext
{
private Context context;
public GXTraceContext(io.opentelemetry.context.Context context)
{
this.context = context;
}
public Context getTraceContext()
{
return this.context;
}
}
186 changes: 186 additions & 0 deletions gxobservability/src/main/java/com/genexus/opentelemetry/OtelSpan.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,186 @@
package com.genexus.opentelemetry;

import java.util.concurrent.atomic.AtomicReference;
import io.opentelemetry.api.trace.Span;
import io.opentelemetry.api.trace.Tracer;
import io.opentelemetry.api.GlobalOpenTelemetry;
import io.opentelemetry.api.OpenTelemetry;
import io.opentelemetry.api.trace.StatusCode;
import io.opentelemetry.context.Context;
import io.opentelemetry.context.Scope;
import io.opentelemetry.extension.annotations.SpanAttribute;
import io.opentelemetry.extension.annotations.WithSpan;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.baggage.Baggage;
import io.opentelemetry.api.baggage.BaggageBuilder;
public class OtelSpan {
private Span span;
public enum SpanStatusCode
{
UNSET,
OK,
ERROR
}
public OtelSpan(Span span)
{
this.span=span;
}
public OtelSpan()
{}
//region EO Properties
public String getTraceId()
{
if (span != null)
return span.getSpanContext().getTraceId();
return "";
}
public String getSpanId()
{
if (span != null)
return span.getSpanContext().getSpanId();
return "";
}
public Boolean isRecording()
{
if (span != null)
return span.isRecording();
return false;
}
public GXSpanContext getSpanContext() {
return new GXSpanContext(getSpanContext(span));
}
//endregion
//region EO Methods
public void endSpan()
{
if (span!=null)
span.end();
}
public GXTraceContext addBaggage(String key, String value)
{
return new GXTraceContext(addBaggageReturnContext(key, value));
}
public String getBaggaeItem(String key,GXTraceContext gxTraceContext)
{
return getBaggaeItemInContext(gxTraceContext.getTraceContext(),key);
}
public GXTraceContext getGXTraceContext()
{
return new GXTraceContext(getContext());
}
public void recordException(String message)
{
recordException(span,new Throwable(message));
}
public void setStringAttribute(String key, String value)
{
if (span != null)
span.setAttribute(key,value);
}
public void setBooleanAttribute(String key, boolean value)
{
if (span != null)
span.setAttribute(key,value);
}
public void setDoubleAttribute(String key, double value)
{
if (span != null)
span.setAttribute(key,value);
}
public void setLongAttribute(String key, long value)
{
if (span != null)
span.setAttribute(key,value);
}
public void setStatus(Byte spanStatusCodeByte)
{
StatusCode statusCode = toStatusCode(spanStatusCodeByte);
if (span != null)
span.setStatus(statusCode);
}
public void setStatus(Byte spanStatusCodeByte, String message)
{
StatusCode statusCode = toStatusCode(spanStatusCodeByte);
if (span != null)
span.setStatus(statusCode, message);
}
//endregion

//region Private methods

private String getBaggaeItemInContext(Context context, String key)
{
AtomicReference<String> value = new AtomicReference<>("");
Baggage.fromContext(context).asMap().forEach((k, v) -> {
if (k.equals(key)) {
value.set(v.getValue());
}
});
if (value != null)
return value.get();
return "";
}
private Context addBaggageReturnContext(String key, String value)
{
Baggage baggage = Baggage.current().toBuilder().put(key,value).build();
return baggage.storeInContext(getContext());
}
private Context getContext()
{
if (span != null)
return Context.current().with(span);
return null;
}
private Context getContextCurrentSpan()
{
return Context.current();
}

private static void recordException(Span span, Throwable exc) {
if (span != null && exc != null) {
span.recordException(exc);
}
}
private io.opentelemetry.api.trace.SpanContext getSpanContext(Span span)
{
if (span != null)
return span.getSpanContext();
return null;
}
private boolean isRecording(Span span)
{
if (span != null)
return span.isRecording();
return false;
}
private Span current()
{
return Span.current();

}
private static StatusCode toStatusCode (Byte spanStatusCode){
switch (spanStatusCode) {
case 0:
return StatusCode.UNSET;
case 1:
return StatusCode.OK;
case 2:
return StatusCode.ERROR;
}
return null;
}
private static SpanStatusCode fromStatusCode (StatusCode statusCode){
switch (statusCode) {
case UNSET:
return SpanStatusCode.UNSET;
case OK:
return SpanStatusCode.OK;
case ERROR:
return SpanStatusCode.ERROR;
}
return null;
}
//endregion

}
Loading