/// <summary> /// Initializes a new instance of the <see cref="OtlpTraceExporter"/> class. /// </summary> /// <param name="options">Configuration options for the exporter.</param> /// <param name="traceServiceClient"><see cref="OtlpCollector.TraceService.TraceServiceClient"/>.</param> internal OtlpTraceExporter(OtlpExporterOptions options, OtlpCollector.TraceService.ITraceServiceClient traceServiceClient = null) { this.options = options ?? throw new ArgumentNullException(nameof(options)); this.headers = options.Headers ?? throw new ArgumentException("Headers were not provided on options.", nameof(options)); if (traceServiceClient != null) { this.traceClient = traceServiceClient; } else { #if NETSTANDARD2_1 this.channel = options.GrpcChannelOptions == default ? GrpcChannel.ForAddress(options.Endpoint) : GrpcChannel.ForAddress(options.Endpoint, options.GrpcChannelOptions); #else this.channel = new Channel(options.Endpoint, options.Credentials, options.ChannelOptions); #endif this.traceClient = new OtlpCollector.TraceService.TraceServiceClient(this.channel); } }
/// <summary> /// Initializes a new instance of the <see cref="OtlpLogExporter"/> class. /// </summary> /// <param name="options">Configuration options for the exporter.</param> /// <param name="traceServiceClient"><see cref="OtlpCollector.LogsService.LogsServiceClient"/>.</param> internal OtlpLogExporter(OtlpExporterOptions options, OtlpCollector.LogsService.ILogsServiceClient traceServiceClient = null) { this.options = options ?? throw new ArgumentNullException(nameof(options)); this.headers = GetMetadataFromHeaders(options.Headers); if (this.options.TimeoutMilliseconds <= 0) { throw new ArgumentException("Timeout value provided is not a positive number.", nameof(this.options.TimeoutMilliseconds)); } if (traceServiceClient != null) { this.logsClient = traceServiceClient; } else { if (options.Endpoint.Scheme != Uri.UriSchemeHttp && options.Endpoint.Scheme != Uri.UriSchemeHttps) { throw new NotSupportedException($"Endpoint URI scheme ({options.Endpoint.Scheme}) is not supported. Currently only \"http\" and \"https\" are supported."); } // #if NETSTANDARD2_1 this.channel = GrpcChannel.ForAddress(options.Endpoint); // #else // ChannelCredentials channelCredentials; // if (options.Endpoint.Scheme == Uri.UriSchemeHttps) // { // channelCredentials = new SslCredentials(); // } // else // { // channelCredentials = ChannelCredentials.Insecure; // } // this.channel = new Channel(options.Endpoint.Authority, channelCredentials); // #endif this.logsClient = new OtlpCollector.LogsService.LogsServiceClient(this.channel); } }
public static Channel CreateChannel(this OtlpExporterOptions options) #endif { if (options.Endpoint.Scheme != Uri.UriSchemeHttp && options.Endpoint.Scheme != Uri.UriSchemeHttps) { throw new NotSupportedException($"Endpoint URI scheme ({options.Endpoint.Scheme}) is not supported. Currently only \"http\" and \"https\" are supported."); } #if NETSTANDARD2_1 || NET5_0_OR_GREATER return(GrpcChannel.ForAddress(options.Endpoint)); #else ChannelCredentials channelCredentials; if (options.Endpoint.Scheme == Uri.UriSchemeHttps) { channelCredentials = new SslCredentials(); } else { channelCredentials = ChannelCredentials.Insecure; } return(new Channel(options.Endpoint.Authority, channelCredentials)); #endif }
public static IExportClient <TraceOtlpCollector.ExportTraceServiceRequest> GetTraceExportClient(this OtlpExporterOptions options) => options.Protocol switch {
public static Metadata GetMetadataFromHeaders(this OtlpExporterOptions options) { return(options.GetHeaders <Metadata>((m, k, v) => m.Add(k, v))); }
public static GrpcChannel CreateChannel(this OtlpExporterOptions options)
/// <summary> /// Initializes a new instance of the <see cref="OtlpTraceExporter"/> class. /// </summary> /// <param name="options">Configuration options for the export.</param> public OtlpTraceExporter(OtlpExporterOptions options) : this(options, null) { }
/// <summary> /// Initializes a new instance of the <see cref="OtlpMetricExporter"/> class. /// </summary> /// <param name="options">Configuration options for the exporter.</param> public OtlpMetricExporter(OtlpExporterOptions options) : this(options, null) { }
/// <summary> /// Initializes a new instance of the <see cref="OtlpLogExporter"/> class. /// </summary> /// <param name="options">Configuration options for the exporter.</param> public OtlpLogExporter(OtlpExporterOptions options) : this(options, null) { }