public static OtlpResource.Resource ToOtlpResource(this Resource resource) { var processResource = new OtlpResource.Resource(); foreach (KeyValuePair <string, object> attribute in resource.Attributes) { var oltpAttribute = attribute.ToOtlpAttribute(); if (oltpAttribute != null) { processResource.Attributes.Add(oltpAttribute); } } if (!processResource.Attributes.Any(kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName)) { var serviceName = (string)ResourceBuilder.CreateDefault().Build().Attributes.FirstOrDefault( kvp => kvp.Key == ResourceSemanticConventions.AttributeServiceName).Value; processResource.Attributes.Add(new OtlpCommon.KeyValue { Key = ResourceSemanticConventions.AttributeServiceName, Value = new OtlpCommon.AnyValue { StringValue = serviceName }, }); } return(processResource); }
internal static IEnumerable <OtlpTrace.ResourceSpans> ToOtlpResourceSpans(this IEnumerable <SpanData> spanDataList) { var resourceToLibraryAndSpans = GroupByResourceAndLibrary(spanDataList); var resourceSpansList = new List <OtlpTrace.ResourceSpans>(resourceToLibraryAndSpans.Count); foreach (var resource in resourceToLibraryAndSpans) { // TODO: this is a temporary workaround since library is still on the resource, not on its own field. var libName = resource.Key.Attributes.FirstOrDefault( kvp => kvp.Key == Resource.LibraryNameKey); var libVersion = resource.Key.Attributes.FirstOrDefault( kvp => kvp.Key == Resource.LibraryVersionKey); var libraryList = new List <OtlpTrace.InstrumentationLibrarySpans>(resource.Value.Count); foreach (var library in resource.Value) { var otlpLibrarySpans = new OtlpTrace.InstrumentationLibrarySpans { InstrumentationLibrary = new OtlpCommon.InstrumentationLibrary { Name = libName.Value?.ToString() ?? string.Empty, Version = libVersion.Value?.ToString() ?? string.Empty, }, }; otlpLibrarySpans.Spans.AddRange(library.Value); libraryList.Add(otlpLibrarySpans); } var otlpResources = new OtlpResource.Resource(); otlpResources.Attributes.AddRange( resource.Key.Attributes.Select(ToOtlpAttribute)); var otlpResourceSpans = new OtlpTrace.ResourceSpans { Resource = otlpResources, }; otlpResourceSpans.InstrumentationLibrarySpans.AddRange(libraryList); resourceSpansList.Add(otlpResourceSpans); } return(resourceSpansList); }
internal static IEnumerable <OtlpTrace.ResourceSpans> ToOtlpResourceSpans(this IEnumerable <Activity> activityBatch) { var resourceToLibraryAndSpans = GroupByResourceAndLibrary(activityBatch); var resourceSpansList = new List <OtlpTrace.ResourceSpans>(resourceToLibraryAndSpans.Count); foreach (var resource in resourceToLibraryAndSpans) { var libraryList = new List <OtlpTrace.InstrumentationLibrarySpans>(resource.Value.Count); foreach (var activitySourceEntry in resource.Value) { var activitySource = activitySourceEntry.Key; var otlpLibrarySpans = new OtlpTrace.InstrumentationLibrarySpans { InstrumentationLibrary = new OtlpCommon.InstrumentationLibrary { Name = activitySource.Name, // Name is enforced to not be null, but it can be empty. Version = activitySource.Version ?? string.Empty, // NRE throw by proto }, }; otlpLibrarySpans.Spans.AddRange(activitySourceEntry.Value); libraryList.Add(otlpLibrarySpans); } var otlpResources = new OtlpResource.Resource(); otlpResources.Attributes.AddRange( resource.Key.Attributes.Select(ToOtlpAttribute).Where(a => a != null)); var otlpResourceSpans = new OtlpTrace.ResourceSpans { Resource = otlpResources, }; otlpResourceSpans.InstrumentationLibrarySpans.AddRange(libraryList); resourceSpansList.Add(otlpResourceSpans); } return(resourceSpansList); }
internal static void AddBatch( this OtlpCollector.ExportTraceServiceRequest request, OtlpResource.Resource processResource, in Batch <Activity> activityBatch)
internal static void AddBatch( this OtlpCollector.ExportLogsServiceRequest request, OtlpResource.Resource processResource, in Batch <LogRecord> activityBatch)
internal static void AddMetrics( this OtlpCollector.ExportMetricsServiceRequest request, OtlpResource.Resource processResource, in Batch <Metric> metrics)