@java.lang.Override public Builder newBuilderForType() { return newBuilder(); }
@Test @SuppressWarnings("all") public void listTracesTest() { String nextPageToken = ""; Trace tracesElement = Trace.newBuilder().build(); List<Trace> traces = Arrays.asList(tracesElement); ListTracesResponse expectedResponse = ListTracesResponse.newBuilder() .setNextPageToken(nextPageToken) .addAllTraces(traces) .build(); mockTraceService.addResponse(expectedResponse); String projectId = "projectId-1969970175"; ListTracesPagedResponse pagedListResponse = client.listTraces(projectId); List<Trace> resources = Lists.newArrayList(pagedListResponse.iterateAll()); Assert.assertEquals(1, resources.size()); Assert.assertEquals(expectedResponse.getTracesList().get(0), resources.get(0)); List<GeneratedMessageV3> actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); ListTracesRequest actualRequest = (ListTracesRequest) actualRequests.get(0); Assert.assertEquals(projectId, actualRequest.getProjectId()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
@Test @SuppressWarnings("all") public void getTraceTest() { String projectId2 = "projectId2939242356"; String traceId2 = "traceId2987826376"; Trace expectedResponse = Trace.newBuilder().setProjectId(projectId2).setTraceId(traceId2).build(); mockTraceService.addResponse(expectedResponse); String projectId = "projectId-1969970175"; String traceId = "traceId1270300245"; Trace actualResponse = client.getTrace(projectId, traceId); Assert.assertEquals(expectedResponse, actualResponse); List<GeneratedMessageV3> actualRequests = mockTraceService.getRequests(); Assert.assertEquals(1, actualRequests.size()); GetTraceRequest actualRequest = (GetTraceRequest) actualRequests.get(0); Assert.assertEquals(projectId, actualRequest.getProjectId()); Assert.assertEquals(traceId, actualRequest.getTraceId()); Assert.assertTrue( channelProvider.isHeaderSent( ApiClientHeaderProvider.getDefaultApiClientHeaderKey(), GaxGrpcProperties.getDefaultApiClientHeaderPattern())); }
/** * Convert a Collection of Zipkin Spans into a Collection of Stackdriver Trace Spans. * * @param zipkinSpans The Collection of Zipkin Spans. * @return A Collection of Stackdriver Trace Spans. */ public Collection<Trace> translateSpans(Collection<Span> zipkinSpans) { List<Span> sortedByTraceAndSpanId = sortByTraceAndSpanId(zipkinSpans); Trace.Builder currentTrace = null; Collection<Trace> translatedTraces = new ArrayList<>(); for (int i = 0, length = sortedByTraceAndSpanId.size(); i < length; i++) { Span currentSpan = sortedByTraceAndSpanId.get(i); // Zipkin trace ID is conditionally 16 or 32 characters, but Stackdriver needs 32 String traceId = currentSpan.traceId(); if (traceId.length() == 16) traceId = "0000000000000000" + traceId; if (currentTrace == null || !traceId.equals(currentTrace.getTraceId())) { finishTrace(currentTrace, translatedTraces); currentTrace = Trace.newBuilder(); currentTrace.setProjectId(this.projectId); currentTrace.setTraceId(traceId); } appendSpan(currentTrace, currentSpan); } finishTrace(currentTrace, translatedTraces); return translatedTraces; }
/** * Returns all of the trace messages in this trace buffer. * * @return an iterable containing the trace messages in this trace buffer. */ public Traces getTraces() { Traces.Builder tracesBuilder = Traces.newBuilder(); for (Map.Entry<TraceKey, SpanBuffer> entry : traceMap.entrySet()) { Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(entry.getKey().getProjectId()) .setTraceId(entry.getKey().getTraceId()); for (TraceSpan.Builder spanBuilder : entry.getValue().getSpans()) { traceBuilder.addSpans(spanBuilder); } tracesBuilder.addTraces(traceBuilder); } return tracesBuilder.build(); }
/** * Returns all of the trace messages in this trace buffer. * * @return an iterable containing the trace messages in this trace buffer. */ public Traces getTraces() { Traces.Builder tracesBuilder = Traces.newBuilder(); for (Map.Entry<TraceKey, SpanBuffer> entry : traceMap.entrySet()) { Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(entry.getKey().getProjectId()) .setTraceId(entry.getKey().getTraceId()); for (TraceSpan.Builder spanBuilder : entry.getValue().getSpans()) { traceBuilder.addSpans(spanBuilder); } tracesBuilder.addTraces(traceBuilder); } return tracesBuilder.build(); }
/** * Returns all of the trace messages in this trace buffer. * * @return an iterable containing the trace messages in this trace buffer. */ public Traces getTraces() { Traces.Builder tracesBuilder = Traces.newBuilder(); for (Map.Entry<TraceKey, SpanBuffer> entry : traceMap.entrySet()) { Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(entry.getKey().getProjectId()) .setTraceId(entry.getKey().getTraceId()); for (TraceSpan.Builder spanBuilder : entry.getValue().getSpans()) { traceBuilder.addSpans(spanBuilder); } tracesBuilder.addTraces(traceBuilder); } return tracesBuilder.build(); }
@Override public void report(Span span) { Assert.notNull(span, "span cannot be null"); if (span.isExportable()) { TraceSpan traceSpan = convert(span); Traces traces = Traces.newBuilder() .addTraces(Trace.newBuilder() .setTraceId(formatTraceId(span)) .setProjectId(this.projectId) .addSpans(traceSpan) .build()) .build(); this.traceConsumer.receive(traces); } else { if (LOGGER.isDebugEnabled()) { LOGGER.debug("The span " + span + " will not be sent to Stackdriver Trace due to sampling"); } } } }
/** * Converts an end span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a trace context that represents the event span. * @param timestamp a timestamp that represents the end time of the event span. * @return a trace message that represents the end span event. */ public Trace generateEndSpan(String projectId, TraceContext context, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setEndTime(toTimestamp(timestamp)); Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts an end span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param timestamp a timestamp that represents the end time of the event span. * @return a trace message that represents the end span event. */ public Trace generateEndSpan(String projectId, SpanContext context, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setEndTime(toTimestamp(timestamp)); Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts an end span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param timestamp a timestamp that represents the end time of the event span. * @return a trace message that represents the end span event. */ public Trace generateEndSpan(String projectId, SpanContext context, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setEndTime(toTimestamp(timestamp)); Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts an end span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param timestamp a timestamp that represents the end time of the event span. * @return a trace message that represents the end span event. */ public Trace generateEndSpan(String projectId, SpanContext context, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setEndTime(toTimestamp(timestamp)); Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a span label annotation event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a trace context that represents the event span. * @param labels a labels containing the label annotations for the event span. * @return a trace message that represents the span label annotation event. */ public Trace generateAnnotateSpan(String projectId, TraceContext context, Labels labels) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder().setSpanId(context.getSpanId().getSpanId()); for (Label label : labels.getLabels()) { spanBuilder.putLabels(label.getKey(), label.getValue()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a span label annotation event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param labels a labels containing the label annotations for the event span. * @return a trace message that represents the span label annotation event. */ public Trace generateAnnotateSpan(String projectId, SpanContext context, Labels labels) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder().setSpanId(context.getSpanId().getSpanId()); for (Label label : labels.getLabels()) { spanBuilder.putLabels(label.getKey(), label.getValue()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a span label annotation event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param labels a labels containing the label annotations for the event span. * @return a trace message that represents the span label annotation event. */ public Trace generateAnnotateSpan(String projectId, SpanContext context, Labels labels) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder().setSpanId(context.getSpanId().getSpanId()); for (Label label : labels.getLabels()) { spanBuilder.putLabels(label.getKey(), label.getValue()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a span label annotation event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param labels a labels containing the label annotations for the event span. * @return a trace message that represents the span label annotation event. */ public Trace generateAnnotateSpan(String projectId, SpanContext context, Labels labels) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder().setSpanId(context.getSpanId().getSpanId()); for (Label label : labels.getLabels()) { spanBuilder.putLabels(label.getKey(), label.getValue()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a start span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param parentContext a span context that represents the parent span of the event span. * @param spanKind the span kind of the event span. * @param name a string containing the name of the event span. * @param timestamp a timestamp that represents the start time of the event span. * @return a trace message that represents the start span event. */ public Trace generateStartSpan(String projectId, SpanContext context, SpanContext parentContext, SpanKind spanKind, String name, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setKind(toSpanKindProto(spanKind)) .setName(name) .setStartTime(toTimestamp(timestamp)); if (parentContext.getTraceId().equals(context.getTraceId()) && parentContext.getSpanId().isValid()) { spanBuilder.setParentSpanId(parentContext.getSpanId().getSpanId()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a start span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param parentContext a span context that represents the parent span of the event span. * @param spanKind the span kind of the event span. * @param name a string containing the name of the event span. * @param timestamp a timestamp that represents the start time of the event span. * @return a trace message that represents the start span event. */ public Trace generateStartSpan(String projectId, SpanContext context, SpanContext parentContext, SpanKind spanKind, String name, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setKind(toSpanKindProto(spanKind)) .setName(name) .setStartTime(toTimestamp(timestamp)); if (parentContext.getTraceId().equals(context.getTraceId()) && parentContext.getSpanId().isValid()) { spanBuilder.setParentSpanId(parentContext.getSpanId().getSpanId()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a start span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a trace context that represents the event span. * @param parentContext a trace context that represents the parent span of the event span. * @param spanKind the span kind of the event span. * @param name a string containing the name of the event span. * @param timestamp a timestamp that represents the start time of the event span. * @return a trace message that represents the start span event. */ public Trace generateStartSpan(String projectId, TraceContext context, TraceContext parentContext, SpanKind spanKind, String name, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setKind(toSpanKindProto(spanKind)) .setName(name) .setStartTime(toTimestamp(timestamp)); if (parentContext.getTraceId().equals(context.getTraceId()) && parentContext.getSpanId().isValid()) { spanBuilder.setParentSpanId(parentContext.getSpanId().getSpanId()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }
/** * Converts a start span event into an API v1 trace message. * * @param projectId a string that contains the Google Cloud Platform project identifier. * @param context a span context that represents the event span. * @param parentContext a span context that represents the parent span of the event span. * @param spanKind the span kind of the event span. * @param name a string containing the name of the event span. * @param timestamp a timestamp that represents the start time of the event span. * @return a trace message that represents the start span event. */ public Trace generateStartSpan(String projectId, SpanContext context, SpanContext parentContext, SpanKind spanKind, String name, Timestamp timestamp) { TraceSpan.Builder spanBuilder = TraceSpan.newBuilder() .setSpanId(context.getSpanId().getSpanId()) .setKind(toSpanKindProto(spanKind)) .setName(name) .setStartTime(toTimestamp(timestamp)); if (parentContext.getTraceId().equals(context.getTraceId()) && parentContext.getSpanId().isValid()) { spanBuilder.setParentSpanId(parentContext.getSpanId().getSpanId()); } Trace.Builder traceBuilder = Trace.newBuilder() .setProjectId(projectId) .setTraceId(formatTraceId(context.getTraceId())) .addSpans(spanBuilder.build()); return traceBuilder.build(); }