Java Code Examples for io.opencensus.tags.TagValue#create()
The following examples show how to use
io.opencensus.tags.TagValue#create() .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: CensusStatsModule.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
ClientCallTracer( CensusStatsModule module, TagContext parentCtx, String fullMethodName, boolean recordStartedRpcs, boolean recordFinishedRpcs) { this.module = module; this.parentCtx = checkNotNull(parentCtx); TagValue methodTag = TagValue.create(fullMethodName); this.startCtx = module.tagger.toBuilder(parentCtx) .put(DeprecatedCensusConstants.RPC_METHOD, methodTag) .build(); this.stopwatch = module.stopwatchSupplier.get().start(); this.recordFinishedRpcs = recordFinishedRpcs; if (recordStartedRpcs) { module.statsRecorder.newMeasureMap() .put(DeprecatedCensusConstants.RPC_CLIENT_STARTED_COUNT, 1) .record(startCtx); } }
Example 2
Source File: CensusStatsModule.java From grpc-nebula-java with Apache License 2.0 | 6 votes |
@Override public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata headers) { TagContext parentCtx = headers.get(statsHeader); if (parentCtx == null) { parentCtx = tagger.empty(); } TagValue methodTag = TagValue.create(fullMethodName); parentCtx = tagger .toBuilder(parentCtx) .put(DeprecatedCensusConstants.RPC_METHOD, methodTag) .build(); return new ServerTracer( CensusStatsModule.this, parentCtx, stopwatchSupplier, tagger, recordStartedRpcs, recordFinishedRpcs); }
Example 3
Source File: CorrelationContextFormat.java From opencensus-java with Apache License 2.0 | 6 votes |
private static void decodeTag(String stringTag, Map<TagKey, TagValueWithMetadata> tags) { String keyWithValue; int firstPropertyIndex = stringTag.indexOf(TAG_PROPERTIES_DELIMITER); if (firstPropertyIndex != -1) { // Tag with properties. keyWithValue = stringTag.substring(0, firstPropertyIndex); // TODO(songya): support decoding tag properties. } else { // Tag without properties. keyWithValue = stringTag; } List<String> keyValuePair = TAG_KEY_VALUE_SPLITTER.splitToList(keyWithValue); checkArgument(keyValuePair.size() == 2, "Malformed tag " + stringTag); TagKey key = TagKey.create(keyValuePair.get(0).trim()); TagValue value = TagValue.create(keyValuePair.get(1).trim()); TagValueWithMetadata valueWithMetadata = TagValueWithMetadata.create(value, METADATA_UNLIMITED_PROPAGATION); tags.put(key, valueWithMetadata); }
Example 4
Source File: OpenCensusMetricExporterSpi.java From ignite with Apache License 2.0 | 6 votes |
/** {@inheritDoc} */ @Override public void spiStart(@Nullable String igniteInstanceName) throws IgniteSpiException { super.spiStart(igniteInstanceName); if (sendInstanceName) { tags.add(INSTANCE_NAME_TAG); instanceNameValue = TagValue.create(igniteInstanceName); } if (sendNodeId) { tags.add(NODE_ID_TAG); nodeIdValue = TagValue.create(((IgniteEx)ignite()).context().localNodeId().toString()); } if (sendConsistentId) { tags.add(CONSISTENT_ID_TAG); //Node consistent id will be known in #onContextInitialized0(IgniteSpiContext), after DiscoMgr started. consistenIdValue = TagValue.create("unknown"); } mreg.addMetricRegistryRemoveListener(mreg -> mreg.forEach(metric -> histogramNames.remove(metric.name()))); }
Example 5
Source File: TagsBenchmark.java From opencensus-java with Apache License 2.0 | 5 votes |
@Setup public void setup() throws Exception { StringBuilder builder = new StringBuilder(size); // build a string with characters from 'a' to 'z' for (int i = 0; i < size; i++) { builder.append((char) (97 + i % 26)); } input = builder.toString(); tagKey = TagKey.create(input); tagValue = TagValue.create(input); }
Example 6
Source File: TagsBenchmarksUtil.java From opencensus-java with Apache License 2.0 | 5 votes |
/** Creates an array of TagValues of 'size' with 'name' prefix. */ @VisibleForTesting public static TagValue[] createTagValues(int size, String name) { TagValue[] values = new TagValue[size]; for (int i = 0; i < size; i++) { values[i] = TagValue.create(name + i); } return values; }
Example 7
Source File: BinarySerializationUtils.java From opencensus-java with Apache License 2.0 | 5 votes |
private static final TagValue createTagValue(TagKey key, String value) throws TagContextDeserializationException { try { return TagValue.create(value); } catch (IllegalArgumentException e) { throw new TagContextDeserializationException( "Invalid tag value for key " + key + ": " + value, e); } }
Example 8
Source File: OpenCensusMetricExporterSpi.java From ignite with Apache License 2.0 | 5 votes |
/** {@inheritDoc} */ @Override protected void onContextInitialized0(IgniteSpiContext spiCtx) throws IgniteSpiException { super.onContextInitialized0(spiCtx); consistenIdValue = TagValue.create( ((IgniteEx)ignite()).context().discovery().localNode().consistentId().toString()); }
Example 9
Source File: CensusStatsModule.java From grpc-java with Apache License 2.0 | 5 votes |
ClientCallTracer(CensusStatsModule module, TagContext parentCtx, String fullMethodName) { this.module = checkNotNull(module); this.parentCtx = checkNotNull(parentCtx); TagValue methodTag = TagValue.create(fullMethodName); this.startCtx = module.tagger.toBuilder(parentCtx) .putLocal(RpcMeasureConstants.GRPC_CLIENT_METHOD, methodTag) .build(); this.stopwatch = module.stopwatchSupplier.get().start(); if (module.recordStartedRpcs) { module.statsRecorder.newMeasureMap() .put(DeprecatedCensusConstants.RPC_CLIENT_STARTED_COUNT, 1) .record(startCtx); } }
Example 10
Source File: CensusStatsModule.java From grpc-java with Apache License 2.0 | 5 votes |
@Override public ServerStreamTracer newServerStreamTracer(String fullMethodName, Metadata headers) { TagContext parentCtx = headers.get(statsHeader); if (parentCtx == null) { parentCtx = tagger.empty(); } TagValue methodTag = TagValue.create(fullMethodName); parentCtx = tagger .toBuilder(parentCtx) .putLocal(RpcMeasureConstants.GRPC_SERVER_METHOD, methodTag) .build(); return new ServerTracer(CensusStatsModule.this, parentCtx); }
Example 11
Source File: CensusStatsModule.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
/** * Record a finished call and mark the current time as the end time. * * <p>Can be called from any thread without synchronization. Calling it the second time or more * is a no-op. */ void callEnded(Status status) { if (callEndedUpdater != null) { if (callEndedUpdater.getAndSet(this, 1) != 0) { return; } } else { if (callEnded != 0) { return; } callEnded = 1; } if (!recordFinishedRpcs) { return; } stopwatch.stop(); long roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS); ClientTracer tracer = streamTracer; if (tracer == null) { tracer = BLANK_CLIENT_TRACER; } MeasureMap measureMap = module.statsRecorder.newMeasureMap() // TODO(songya): remove the deprecated measure constants once they are completed removed. .put(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT, 1) // The latency is double value .put( DeprecatedCensusConstants.RPC_CLIENT_ROUNDTRIP_LATENCY, roundtripNanos / NANOS_PER_MILLI) .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_COUNT, tracer.outboundMessageCount) .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_COUNT, tracer.inboundMessageCount) .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_BYTES, tracer.outboundWireSize) .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_BYTES, tracer.inboundWireSize) .put( DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES, tracer.outboundUncompressedSize) .put( DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES, tracer.inboundUncompressedSize); if (!status.isOk()) { measureMap.put(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT, 1); } TagValue statusTag = TagValue.create(status.getCode().toString()); measureMap.record( module .tagger .toBuilder(startCtx) .put(DeprecatedCensusConstants.RPC_STATUS, statusTag) .build()); }
Example 12
Source File: CensusStatsModule.java From grpc-nebula-java with Apache License 2.0 | 4 votes |
/** * Record a finished stream and mark the current time as the end time. * * <p>Can be called from any thread without synchronization. Calling it the second time or more * is a no-op. */ @Override public void streamClosed(Status status) { if (streamClosedUpdater != null) { if (streamClosedUpdater.getAndSet(this, 1) != 0) { return; } } else { if (streamClosed != 0) { return; } streamClosed = 1; } if (!recordFinishedRpcs) { return; } stopwatch.stop(); long elapsedTimeNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS); MeasureMap measureMap = module.statsRecorder.newMeasureMap() // TODO(songya): remove the deprecated measure constants once they are completed removed. .put(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT, 1) // The latency is double value .put( DeprecatedCensusConstants.RPC_SERVER_SERVER_LATENCY, elapsedTimeNanos / NANOS_PER_MILLI) .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_COUNT, outboundMessageCount) .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_COUNT, inboundMessageCount) .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_BYTES, outboundWireSize) .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_BYTES, inboundWireSize) .put( DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES, outboundUncompressedSize) .put( DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES, inboundUncompressedSize); if (!status.isOk()) { measureMap.put(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT, 1); } TagValue statusTag = TagValue.create(status.getCode().toString()); measureMap.record( module .tagger .toBuilder(parentCtx) .put(DeprecatedCensusConstants.RPC_STATUS, statusTag) .build()); }
Example 13
Source File: TagsBenchmark.java From opencensus-java with Apache License 2.0 | 4 votes |
@Benchmark @BenchmarkMode(Mode.AverageTime) @OutputTimeUnit(TimeUnit.NANOSECONDS) public TagValue tagValueCreation(Data data) { return TagValue.create("val"); }
Example 14
Source File: CensusStatsModule.java From grpc-java with Apache License 2.0 | 4 votes |
/** * Record a finished call and mark the current time as the end time. * * <p>Can be called from any thread without synchronization. Calling it the second time or more * is a no-op. */ void callEnded(Status status) { if (callEndedUpdater != null) { if (callEndedUpdater.getAndSet(this, 1) != 0) { return; } } else { if (callEnded != 0) { return; } callEnded = 1; } if (!module.recordFinishedRpcs) { return; } stopwatch.stop(); long roundtripNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS); ClientTracer tracer = streamTracer; if (tracer == null) { tracer = new ClientTracer(module, startCtx); } MeasureMap measureMap = module.statsRecorder.newMeasureMap() // TODO(songya): remove the deprecated measure constants once they are completed removed. .put(DeprecatedCensusConstants.RPC_CLIENT_FINISHED_COUNT, 1) // The latency is double value .put( DeprecatedCensusConstants.RPC_CLIENT_ROUNDTRIP_LATENCY, roundtripNanos / NANOS_PER_MILLI) .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_COUNT, tracer.outboundMessageCount) .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_COUNT, tracer.inboundMessageCount) .put(DeprecatedCensusConstants.RPC_CLIENT_REQUEST_BYTES, tracer.outboundWireSize) .put(DeprecatedCensusConstants.RPC_CLIENT_RESPONSE_BYTES, tracer.inboundWireSize) .put( DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_REQUEST_BYTES, tracer.outboundUncompressedSize) .put( DeprecatedCensusConstants.RPC_CLIENT_UNCOMPRESSED_RESPONSE_BYTES, tracer.inboundUncompressedSize); if (!status.isOk()) { measureMap.put(DeprecatedCensusConstants.RPC_CLIENT_ERROR_COUNT, 1); } TagValue statusTag = TagValue.create(status.getCode().toString()); measureMap.record( module .tagger .toBuilder(startCtx) .putLocal(RpcMeasureConstants.GRPC_CLIENT_STATUS, statusTag) .build()); }
Example 15
Source File: CensusStatsModule.java From grpc-java with Apache License 2.0 | 4 votes |
/** * Record a finished stream and mark the current time as the end time. * * <p>Can be called from any thread without synchronization. Calling it the second time or more * is a no-op. */ @Override public void streamClosed(Status status) { if (streamClosedUpdater != null) { if (streamClosedUpdater.getAndSet(this, 1) != 0) { return; } } else { if (streamClosed != 0) { return; } streamClosed = 1; } if (!module.recordFinishedRpcs) { return; } stopwatch.stop(); long elapsedTimeNanos = stopwatch.elapsed(TimeUnit.NANOSECONDS); MeasureMap measureMap = module.statsRecorder.newMeasureMap() // TODO(songya): remove the deprecated measure constants once they are completed removed. .put(DeprecatedCensusConstants.RPC_SERVER_FINISHED_COUNT, 1) // The latency is double value .put( DeprecatedCensusConstants.RPC_SERVER_SERVER_LATENCY, elapsedTimeNanos / NANOS_PER_MILLI) .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_COUNT, outboundMessageCount) .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_COUNT, inboundMessageCount) .put(DeprecatedCensusConstants.RPC_SERVER_RESPONSE_BYTES, outboundWireSize) .put(DeprecatedCensusConstants.RPC_SERVER_REQUEST_BYTES, inboundWireSize) .put( DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_RESPONSE_BYTES, outboundUncompressedSize) .put( DeprecatedCensusConstants.RPC_SERVER_UNCOMPRESSED_REQUEST_BYTES, inboundUncompressedSize); if (!status.isOk()) { measureMap.put(DeprecatedCensusConstants.RPC_SERVER_ERROR_COUNT, 1); } TagValue statusTag = TagValue.create(status.getCode().toString()); measureMap.record( module .tagger .toBuilder(parentCtx) .putLocal(RpcMeasureConstants.GRPC_SERVER_STATUS, statusTag) .build()); }