You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@rocketmq.apache.org by li...@apache.org on 2022/06/28 08:47:43 UTC

[rocketmq-client-csharp] branch observability updated: Add custom otlp exporter

This is an automated email from the ASF dual-hosted git repository.

lizhanhui pushed a commit to branch observability
in repository https://gitbox.apache.org/repos/asf/rocketmq-client-csharp.git


The following commit(s) were added to refs/heads/observability by this push:
     new f77a593  Add custom otlp exporter
f77a593 is described below

commit f77a593b12620afd3fc79e2a0aa8a5114d7f7338
Author: Li Zhanhui <li...@gmail.com>
AuthorDate: Tue Jun 28 16:47:33 2022 +0800

    Add custom otlp exporter
---
 rocketmq-client-csharp/Producer.cs                   | 7 +++++++
 rocketmq-client-csharp/rocketmq-client-csharp.csproj | 1 +
 2 files changed, 8 insertions(+)

diff --git a/rocketmq-client-csharp/Producer.cs b/rocketmq-client-csharp/Producer.cs
index 93938cd..bd24251 100644
--- a/rocketmq-client-csharp/Producer.cs
+++ b/rocketmq-client-csharp/Producer.cs
@@ -26,6 +26,7 @@ using Google.Protobuf;
 using Google.Protobuf.WellKnownTypes;
 using Grpc.Core;
 using NLog;
+using OpenTelemetry.Exporter;
 
 namespace Org.Apache.Rocketmq
 {
@@ -34,6 +35,8 @@ namespace Org.Apache.Rocketmq
         public Producer(AccessPoint accessPoint, string resourceNamespace) : base(accessPoint, resourceNamespace)
         {
             _loadBalancer = new ConcurrentDictionary<string, PublishLoadBalancer>();
+            _otlpExporterOptions = new OtlpExporterOptions();
+            _otlpExporterOptions.Protocol = OtlpExportProtocol.Grpc;
             _sendFailureTotal = MetricMeter.CreateCounter<long>("rocketmq_send_failure_total");
             _sendLatency = MetricMeter.CreateHistogram<double>("rocketmq_send_success_cost_time", 
                 description: "Measure the duration of publishing messages to brokers",
@@ -44,6 +47,9 @@ namespace Org.Apache.Rocketmq
         {
             await base.Start();
             // More initialization
+            _otlpExporterOptions.TimeoutMilliseconds = (int)_clientSettings.RequestTimeout.ToTimeSpan().TotalMilliseconds;
+            _otlpExporterOptions.Endpoint = new(_accessPoint.TargetUrl());
+            // TODO: Add authentication header
         }
 
         public override async Task Shutdown()
@@ -176,5 +182,6 @@ namespace Org.Apache.Rocketmq
 
         private readonly Counter<long> _sendFailureTotal;
         private readonly Histogram<double> _sendLatency;
+        private readonly OtlpExporterOptions _otlpExporterOptions;
     }
 }
\ No newline at end of file
diff --git a/rocketmq-client-csharp/rocketmq-client-csharp.csproj b/rocketmq-client-csharp/rocketmq-client-csharp.csproj
index cc81ff7..86fa88b 100644
--- a/rocketmq-client-csharp/rocketmq-client-csharp.csproj
+++ b/rocketmq-client-csharp/rocketmq-client-csharp.csproj
@@ -21,6 +21,7 @@
     <PackageReference Include="NLog" Version="4.7.13" />
     <PackageReference Include="OpenTelemetry" Version="1.3.0" />
     <PackageReference Include="OpenTelemetry.Api" Version="1.3.0" />
+    <PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.3.0" />
 
     <Protobuf Include="Protos\apache\rocketmq\v2\definition.proto" ProtoRoot="Protos" GrpcServices="Client" />
     <Protobuf Include="Protos\google\rpc\code.proto" ProtoRoot="Protos" GrpcServices="Client" />