Search in sources :

Example 6 with Span

use of io.opentelemetry.api.trace.Span in project hbase by apache.

the class AsyncRegionLocator method getRegionLocation.

CompletableFuture<HRegionLocation> getRegionLocation(TableName tableName, byte[] row, int replicaId, RegionLocateType type, boolean reload, long timeoutNs) {
    final Supplier<Span> supplier = new TableSpanBuilder(conn).setName("AsyncRegionLocator.getRegionLocation").setTableName(tableName);
    return tracedLocationFuture(() -> {
        // meta region can not be split right now so we always call the same method.
        // Change it later if the meta table can have more than one regions.
        CompletableFuture<HRegionLocation> future = new CompletableFuture<>();
        CompletableFuture<RegionLocations> locsFuture = isMeta(tableName) ? metaRegionLocator.getRegionLocations(replicaId, reload) : nonMetaRegionLocator.getRegionLocations(tableName, row, replicaId, type, reload);
        addListener(locsFuture, (locs, error) -> {
            if (error != null) {
                future.completeExceptionally(error);
                return;
            }
            HRegionLocation loc = locs.getRegionLocation(replicaId);
            if (loc == null) {
                future.completeExceptionally(new RegionOfflineException("No location for " + tableName + ", row='" + Bytes.toStringBinary(row) + "', locateType=" + type + ", replicaId=" + replicaId));
            } else if (loc.getServerName() == null) {
                future.completeExceptionally(new RegionOfflineException("No server address listed for region '" + loc.getRegion().getRegionNameAsString() + ", row='" + Bytes.toStringBinary(row) + "', locateType=" + type + ", replicaId=" + replicaId));
            } else {
                future.complete(loc);
            }
        });
        return withTimeout(future, timeoutNs, () -> "Timeout(" + TimeUnit.NANOSECONDS.toMillis(timeoutNs) + "ms) waiting for region location for " + tableName + ", row='" + Bytes.toStringBinary(row) + "', replicaId=" + replicaId);
    }, AsyncRegionLocator::getRegionNames, supplier);
}
Also used : RegionLocations(org.apache.hadoop.hbase.RegionLocations) CompletableFuture(java.util.concurrent.CompletableFuture) HRegionLocation(org.apache.hadoop.hbase.HRegionLocation) TableSpanBuilder(org.apache.hadoop.hbase.client.trace.TableSpanBuilder) Span(io.opentelemetry.api.trace.Span)

Example 7 with Span

use of io.opentelemetry.api.trace.Span in project hbase by apache.

the class IntegrationTestSendTraceRequests method insertData.

private LinkedBlockingQueue<Long> insertData() throws IOException, InterruptedException {
    LinkedBlockingQueue<Long> rowKeys = new LinkedBlockingQueue<>(25000);
    BufferedMutator ht = util.getConnection().getBufferedMutator(this.tableName);
    byte[] value = new byte[300];
    for (int x = 0; x < 5000; x++) {
        Span span = TraceUtil.getGlobalTracer().spanBuilder("insertData").startSpan();
        try (Scope scope = span.makeCurrent()) {
            for (int i = 0; i < 5; i++) {
                long rk = random.nextLong();
                rowKeys.add(rk);
                Put p = new Put(Bytes.toBytes(rk));
                for (int y = 0; y < 10; y++) {
                    random.nextBytes(value);
                    p.addColumn(familyName, Bytes.toBytes(random.nextLong()), value);
                }
                ht.mutate(p);
            }
            if ((x % 1000) == 0) {
                admin.flush(tableName);
            }
        } finally {
            span.end();
        }
    }
    admin.flush(tableName);
    return rowKeys;
}
Also used : Scope(io.opentelemetry.context.Scope) BufferedMutator(org.apache.hadoop.hbase.client.BufferedMutator) LinkedBlockingQueue(java.util.concurrent.LinkedBlockingQueue) Span(io.opentelemetry.api.trace.Span) Put(org.apache.hadoop.hbase.client.Put)

Example 8 with Span

use of io.opentelemetry.api.trace.Span in project wildfly by wildfly.

the class OpenTelemetryContainerFilter method filter.

@Override
public void filter(ContainerRequestContext containerRequestContext, ContainerResponseContext containerResponseContext) {
    Object serverSpan = containerRequestContext.getProperty(SERVER_SPAN);
    if (serverSpan != null && serverSpan instanceof Span) {
        final Span span = (Span) serverSpan;
        final int status = containerResponseContext.getStatus();
        if (status >= 400) {
            span.setAttribute(SemanticAttributes.HTTP_STATUS_CODE, status);
        }
        span.end();
    }
}
Also used : Span(io.opentelemetry.api.trace.Span)

Example 9 with Span

use of io.opentelemetry.api.trace.Span in project wildfly by wildfly.

the class Service1 method endpoint1.

@GET
public String endpoint1() throws JsonProcessingException {
    final Span span = tracer.spanBuilder("Doing some work").startSpan();
    span.makeCurrent();
    String traceParent = sendRequest();
    span.end();
    Map<String, String> values = new HashMap<>();
    values.put("traceId", span.getSpanContext().getTraceId());
    values.put("traceParent", traceParent);
    ObjectMapper objectMapper = new ObjectMapper();
    return objectMapper.writeValueAsString(values);
}
Also used : HashMap(java.util.HashMap) Span(io.opentelemetry.api.trace.Span) ObjectMapper(com.fasterxml.jackson.databind.ObjectMapper) GET(javax.ws.rs.GET)

Example 10 with Span

use of io.opentelemetry.api.trace.Span in project wildfly by wildfly.

the class Service2 method endpoint1.

@GET
public String endpoint1() {
    final Span span = tracer.spanBuilder("Doing some work in service2").startSpan();
    String traceParent = headers.getHeaderString(TRACE_PARENT);
    if (traceParent == null || traceParent.isEmpty()) {
        throw new WebApplicationException("Missing traceparent header");
    }
    span.end();
    return traceParent;
}
Also used : WebApplicationException(javax.ws.rs.WebApplicationException) Span(io.opentelemetry.api.trace.Span) GET(javax.ws.rs.GET)

Aggregations

Span (io.opentelemetry.api.trace.Span)28 Scope (io.opentelemetry.context.Scope)21 IOException (java.io.IOException)7 LinkedBlockingQueue (java.util.concurrent.LinkedBlockingQueue)3 RetryCounter (org.apache.hadoop.hbase.util.RetryCounter)3 KeeperException (org.apache.zookeeper.KeeperException)3 Context (io.opentelemetry.context.Context)2 TextMapGetter (io.opentelemetry.context.propagation.TextMapGetter)2 InetSocketAddress (java.net.InetSocketAddress)2 CompletableFuture (java.util.concurrent.CompletableFuture)2 GET (javax.ws.rs.GET)2 CellScanner (org.apache.hadoop.hbase.CellScanner)2 Result (org.apache.hadoop.hbase.client.Result)2 Table (org.apache.hadoop.hbase.client.Table)2 Message (org.apache.hbase.thirdparty.com.google.protobuf.Message)2 ConsoleReporter (com.codahale.metrics.ConsoleReporter)1 ObjectMapper (com.fasterxml.jackson.databind.ObjectMapper)1 OpenTelemetry (io.opentelemetry.api.OpenTelemetry)1 SpanBuilder (io.opentelemetry.api.trace.SpanBuilder)1 StatusCode (io.opentelemetry.api.trace.StatusCode)1