@Override public boolean isEmpty() { final StringMap map = localMap.get(); return map == null || map.size() == 0; }
@Override public boolean isEmpty() { final StringMap map = localMap.get(); return map == null || map.size() == 0; }
@Override public boolean isEmpty() { final StringMap map = localMap.get(); return map == null || map.size() == 0; }
@Override public boolean isEmpty() { final StringMap map = localMap.get(); return map == null || map.size() == 0; }
/** * If there are no configuration properties, this injector will return the thread context's internal data * structure. Otherwise the configuration properties are combined with the thread context key-value pairs into the * specified reusable StringMap. * * @param props list of configuration properties, may be {@code null} * @param ignore a {@code StringMap} instance from the log event * @return a {@code StringMap} combining configuration properties with thread context data */ @Override public StringMap injectContextData(final List<Property> props, final StringMap ignore) { // If there are no configuration properties we want to just return the ThreadContext's StringMap: // it is a copy-on-write data structure so we are sure ThreadContext changes will not affect our copy. final StringMap immutableCopy = ThreadContext.getThreadContextMap().getReadOnlyContextData(); if (props == null || props.isEmpty()) { return immutableCopy; // this will replace the LogEvent's context data with the returned instance } // However, if the list of Properties is non-empty we need to combine the properties and the ThreadContext // data. Note that we cannot reuse the specified StringMap: some Loggers may have properties defined // and others not, so the LogEvent's context data may have been replaced with an immutable copy from // the ThreadContext - this will throw an UnsupportedOperationException if we try to modify it. final StringMap result = ContextDataFactory.createContextData(props.size() + immutableCopy.size()); copyProperties(props, result); result.putAll(immutableCopy); return result; }
static StringMap getContextAndTracingData() { SpanContext spanContext = getCurrentSpanContext(); ReadOnlyThreadContextMap context = ThreadContext.getThreadContextMap(); SortedArrayStringMap stringMap; if (context == null) { stringMap = new SortedArrayStringMap(ThreadContext.getImmutableContext()); } else { StringMap contextData = context.getReadOnlyContextData(); stringMap = new SortedArrayStringMap(contextData.size() + 3); stringMap.putAll(contextData); } // TODO(sebright): Move the calls to TraceId.toLowerBase16() and SpanId.toLowerBase16() out of // the critical path by wrapping the trace and span IDs in objects that call toLowerBase16() in // their toString() methods, after there is a fix for // https://github.com/census-instrumentation/opencensus-java/issues/1436. stringMap.putValue( OpenCensusTraceContextDataInjector.TRACE_ID_CONTEXT_KEY, spanContext.getTraceId().toLowerBase16()); stringMap.putValue( OpenCensusTraceContextDataInjector.SPAN_ID_CONTEXT_KEY, spanContext.getSpanId().toLowerBase16()); stringMap.putValue( OpenCensusTraceContextDataInjector.TRACE_SAMPLED_CONTEXT_KEY, spanContext.getTraceOptions().isSampled() ? "true" : "false"); return stringMap; }