Many resources are needed to download a project. Please understand that we have to compensate our server costs. Thank you in advance. Project price only 1 $
You can buy this project and download/modify it how often you want.
/*-
* Copyright (C) 2022 Vaadin Ltd
*
* This program is available under Vaadin Commercial License and Service Terms.
*
*
* See for the full
* license.
*/
package com.vaadin.extension.instrumentation.client;
import java.util.AbstractMap;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
import java.util.List;
import java.util.Map;
import io.opentelemetry.api.common.AttributeKey;
import io.opentelemetry.api.common.Attributes;
import io.opentelemetry.api.common.AttributesBuilder;
import io.opentelemetry.api.trace.SpanContext;
import io.opentelemetry.api.trace.SpanKind;
import io.opentelemetry.api.trace.TraceFlags;
import io.opentelemetry.api.trace.TraceState;
import io.opentelemetry.sdk.common.InstrumentationLibraryInfo;
import io.opentelemetry.sdk.common.InstrumentationScopeInfo;
import io.opentelemetry.sdk.resources.Resource;
import io.opentelemetry.sdk.resources.ResourceBuilder;
import io.opentelemetry.sdk.trace.data.EventData;
import io.opentelemetry.sdk.trace.data.LinkData;
import io.opentelemetry.sdk.trace.data.SpanData;
import io.opentelemetry.sdk.trace.data.StatusData;
import com.vaadin.extension.Constants;
/**
* This represents the data for an observability span. It is constructed from a
* map of objects sent by the Frontend Observability module.
*/
public class ObjectMapSpanData implements SpanData {
private final SpanContext spanContext;
private final SpanContext parentSpanContext;
private final Resource resource;
private final InstrumentationLibraryInfo instrumentationLibraryInfo;
private final InstrumentationScopeInfo instrumentationScopeInfo;
private final String name;
private final SpanKind kind;
private final long startEpochNanos;
private final long endEpochNanos;
private final Attributes attributes;
private final List events;
private final List links;
private final StatusData status;
/**
* This takes the ID of the installed handler and three object maps
* representing the resource, scope and span of the observability trace.
*
* @param frontendId The ID of the observability handler
* @param resource The resource object map
* @param scope The scope object map
* @param span The span object map
*/
@SuppressWarnings("unchecked")
public ObjectMapSpanData(String frontendId, Map resource,
Map scope, Map span) {
String traceId = (String) span.get("traceId");
String spanId = (String) span.get("spanId");
this.spanContext = SpanContext.create(traceId, spanId,
TraceFlags.getDefault(), TraceState.getDefault());
String parentSpanId = (String) span.get("parentSpanId");
this.parentSpanContext = SpanContext.create(traceId, parentSpanId,
TraceFlags.getDefault(), TraceState.getDefault());
ResourceBuilder resourceBuilder = Resource.builder();
this.resource = resourceBuilder
.putAll(getAttributes(resource).build())
.build();
this.instrumentationLibraryInfo =
InstrumentationLibraryInfo.create(
(String) scope.get("name"),
(String) scope.get("version"));
this.instrumentationScopeInfo = InstrumentationScopeInfo.create(
(String) scope.get("name"), (String) scope.get("version"),
null);
this.name = "Frontend: " + span.get("name");
this.kind = SpanKind.CLIENT;
this.startEpochNanos = (long) span.get("startTimeUnixNano");
this.endEpochNanos = (long) span.get("endTimeUnixNano");
AttributesBuilder attributesBuilder = getAttributes(span);
this.attributes = attributesBuilder
.put(Constants.FRONTEND_ID, frontendId)
.build();
this.events = new ArrayList<>();
for (Map event :
(Collection