Skip to content

Commit 950c616

Browse files
authored
Improvements to the OTLP trace example (#3141)
1 parent 4384c3c commit 950c616

File tree

3 files changed

+24
-12
lines changed

3 files changed

+24
-12
lines changed

examples/Console/Program.cs

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -27,14 +27,18 @@ public class Program
2727
/// Main method - invoke this using command line.
2828
/// For example:
2929
///
30-
/// dotnet run --project Examples.Console.csproj console
31-
/// dotnet run --project Examples.Console.csproj inmemory
32-
/// dotnet run --project Examples.Console.csproj zipkin -u http://localhost:9411/api/v2/spans
33-
/// dotnet run --project Examples.Console.csproj jaeger -h localhost -p 6831
34-
/// dotnet run --project Examples.Console.csproj prometheus -p 9464
35-
/// dotnet run --project Examples.Console.csproj otlp -e "http://localhost:4317" -p "grpc"
36-
/// dotnet run --project Examples.Console.csproj zpages
37-
/// dotnet run --project Examples.Console.csproj metrics --help
30+
/// dotnet run --project Examples.Console.csproj -- console
31+
/// dotnet run --project Examples.Console.csproj -- inmemory
32+
/// dotnet run --project Examples.Console.csproj -- zipkin -u http://localhost:9411/api/v2/spans
33+
/// dotnet run --project Examples.Console.csproj -- jaeger -h localhost -p 6831
34+
/// dotnet run --project Examples.Console.csproj -- prometheus -p 9464
35+
/// dotnet run --project Examples.Console.csproj -- otlp -e "http://localhost:4317" -p "grpc"
36+
/// dotnet run --project Examples.Console.csproj -- zpages
37+
/// dotnet run --project Examples.Console.csproj -- metrics --help
38+
///
39+
/// To see all available examples in the project run:
40+
///
41+
/// dotnet run --project Examples.Console.csproj -- --help
3842
///
3943
/// The above must be run from the project root folder
4044
/// (eg: C:\repos\opentelemetry-dotnet\examples\Console\).
@@ -153,7 +157,7 @@ internal class OpenTracingShimOptions
153157
[Verb("otlp", HelpText = "Specify the options required to test OpenTelemetry Protocol (OTLP)")]
154158
internal class OtlpOptions
155159
{
156-
[Option('e', "endpoint", HelpText = "Target to which the exporter is going to send traces or metrics", Default = "http://localhost:4317")]
160+
[Option('e', "endpoint", HelpText = "Target to which the exporter is going to send traces or metrics (default value depends on protocol).", Default = null)]
157161
public string Endpoint { get; set; }
158162

159163
[Option('p', "protocol", HelpText = "Transport protocol used by exporter. Supported values: grpc and http/protobuf.", Default = "grpc")]

examples/Console/TestOtlpExporter.cs

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -34,10 +34,10 @@ internal static object Run(string endpoint, string protocol)
3434
* launch the OpenTelemetry Collector with an OTLP receiver, by running:
3535
*
3636
* - On Unix based systems use:
37-
* docker run --rm -it -p 4317:4317 -v $(pwd):/cfg otel/opentelemetry-collector:0.33.0 --config=/cfg/otlp-collector-example/config.yaml
37+
* docker run --rm -it -p 4317:4317 -p 4318:4318 -v $(pwd):/cfg otel/opentelemetry-collector:0.48.0 --config=/cfg/otlp-collector-example/config.yaml
3838
*
3939
* - On Windows use:
40-
* docker run --rm -it -p 4317:4317 -v "%cd%":/cfg otel/opentelemetry-collector:0.33.0 --config=/cfg/otlp-collector-example/config.yaml
40+
* docker run --rm -it -p 4317:4317 -p 4318:4318 -v "%cd%":/cfg otel/opentelemetry-collector:0.48.0 --config=/cfg/otlp-collector-example/config.yaml
4141
*
4242
* Open another terminal window at the examples/Console/ directory and
4343
* launch the OTLP example by running:
@@ -74,8 +74,15 @@ private static object RunWithActivitySource(string endpoint, string protocol)
7474
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
7575
.AddOtlpExporter(opt =>
7676
{
77-
opt.Endpoint = new Uri(endpoint);
77+
// If endpoint was not specified, the proper one will be selected according to the protocol.
78+
if (!string.IsNullOrEmpty(endpoint))
79+
{
80+
opt.Endpoint = new Uri(endpoint);
81+
}
82+
7883
opt.Protocol = otlpExportProtocol.Value;
84+
85+
System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
7986
})
8087
.Build();
8188

examples/Console/otlp-collector-example/config.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ receivers:
88
otlp:
99
protocols:
1010
grpc:
11+
http:
1112

1213
exporters:
1314
logging:

0 commit comments

Comments
 (0)