/** * * * <pre> * List of trace records returned. * </pre> * * <code>repeated .google.devtools.cloudtrace.v1.Trace traces = 1;</code> */ public Builder addTraces( int index, com.google.devtools.cloudtrace.v1.Trace.Builder builderForValue) { if (tracesBuilder_ == null) { ensureTracesIsMutable(); traces_.add(index, builderForValue.build()); onChanged(); } else { tracesBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * List of trace records returned. * </pre> * * <code>repeated .google.devtools.cloudtrace.v1.Trace traces = 1;</code> */ public Builder setTraces( int index, com.google.devtools.cloudtrace.v1.Trace.Builder builderForValue) { if (tracesBuilder_ == null) { ensureTracesIsMutable(); traces_.set(index, builderForValue.build()); onChanged(); } else { tracesBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * List of traces. * </pre> * * <code>repeated .google.devtools.cloudtrace.v1.Trace traces = 1;</code> */ public Builder setTraces( int index, com.google.devtools.cloudtrace.v1.Trace.Builder builderForValue) { if (tracesBuilder_ == null) { ensureTracesIsMutable(); traces_.set(index, builderForValue.build()); onChanged(); } else { tracesBuilder_.setMessage(index, builderForValue.build()); } return this; } /**
/** * 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(); }
/** * 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(); }
@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 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 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 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(); }
private void finishTrace(Trace.Builder traceBuilder, Collection<Trace> convertedTraces) { if (traceBuilder != null) { convertedTraces.add(traceBuilder.build()); } } }
@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())); }
/** * * * <pre> * List of traces. * </pre> * * <code>repeated .google.devtools.cloudtrace.v1.Trace traces = 1;</code> */ public Builder addTraces( int index, com.google.devtools.cloudtrace.v1.Trace.Builder builderForValue) { if (tracesBuilder_ == null) { ensureTracesIsMutable(); traces_.add(index, builderForValue.build()); onChanged(); } else { tracesBuilder_.addMessage(index, builderForValue.build()); } return this; } /**
/** * * * <pre> * List of trace records returned. * </pre> * * <code>repeated .google.devtools.cloudtrace.v1.Trace traces = 1;</code> */ public Builder addTraces(com.google.devtools.cloudtrace.v1.Trace.Builder builderForValue) { if (tracesBuilder_ == null) { ensureTracesIsMutable(); traces_.add(builderForValue.build()); onChanged(); } else { tracesBuilder_.addMessage(builderForValue.build()); } return this; } /**
/** * * * <pre> * List of traces. * </pre> * * <code>repeated .google.devtools.cloudtrace.v1.Trace traces = 1;</code> */ public Builder addTraces(com.google.devtools.cloudtrace.v1.Trace.Builder builderForValue) { if (tracesBuilder_ == null) { ensureTracesIsMutable(); traces_.add(builderForValue.build()); onChanged(); } else { tracesBuilder_.addMessage(builderForValue.build()); } return this; } /**