Improvements to the OTLP trace example (#3141)

This commit is contained in:
Paulo Janotti 2022-04-05 22:29:11 -07:00 committed by GitHub
parent 4384c3ceef
commit 950c6162b4
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
3 changed files with 24 additions and 12 deletions

View File

@ -27,14 +27,18 @@ namespace Examples.Console
/// Main method - invoke this using command line.
/// For example:
///
/// dotnet run --project Examples.Console.csproj console
/// dotnet run --project Examples.Console.csproj inmemory
/// dotnet run --project Examples.Console.csproj zipkin -u http://localhost:9411/api/v2/spans
/// dotnet run --project Examples.Console.csproj jaeger -h localhost -p 6831
/// dotnet run --project Examples.Console.csproj prometheus -p 9464
/// dotnet run --project Examples.Console.csproj otlp -e "http://localhost:4317" -p "grpc"
/// dotnet run --project Examples.Console.csproj zpages
/// dotnet run --project Examples.Console.csproj metrics --help
/// dotnet run --project Examples.Console.csproj -- console
/// dotnet run --project Examples.Console.csproj -- inmemory
/// dotnet run --project Examples.Console.csproj -- zipkin -u http://localhost:9411/api/v2/spans
/// dotnet run --project Examples.Console.csproj -- jaeger -h localhost -p 6831
/// dotnet run --project Examples.Console.csproj -- prometheus -p 9464
/// dotnet run --project Examples.Console.csproj -- otlp -e "http://localhost:4317" -p "grpc"
/// dotnet run --project Examples.Console.csproj -- zpages
/// dotnet run --project Examples.Console.csproj -- metrics --help
///
/// To see all available examples in the project run:
///
/// dotnet run --project Examples.Console.csproj -- --help
///
/// The above must be run from the project root folder
/// (eg: C:\repos\opentelemetry-dotnet\examples\Console\).
@ -153,7 +157,7 @@ namespace Examples.Console
[Verb("otlp", HelpText = "Specify the options required to test OpenTelemetry Protocol (OTLP)")]
internal class OtlpOptions
{
[Option('e', "endpoint", HelpText = "Target to which the exporter is going to send traces or metrics", Default = "http://localhost:4317")]
[Option('e', "endpoint", HelpText = "Target to which the exporter is going to send traces or metrics (default value depends on protocol).", Default = null)]
public string Endpoint { get; set; }
[Option('p', "protocol", HelpText = "Transport protocol used by exporter. Supported values: grpc and http/protobuf.", Default = "grpc")]

View File

@ -34,10 +34,10 @@ namespace Examples.Console
* launch the OpenTelemetry Collector with an OTLP receiver, by running:
*
* - On Unix based systems use:
* docker run --rm -it -p 4317:4317 -v $(pwd):/cfg otel/opentelemetry-collector:0.33.0 --config=/cfg/otlp-collector-example/config.yaml
* 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
*
* - On Windows use:
* docker run --rm -it -p 4317:4317 -v "%cd%":/cfg otel/opentelemetry-collector:0.33.0 --config=/cfg/otlp-collector-example/config.yaml
* 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
*
* Open another terminal window at the examples/Console/ directory and
* launch the OTLP example by running:
@ -73,9 +73,16 @@ namespace Examples.Console
.AddSource("Samples.SampleClient", "Samples.SampleServer")
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
.AddOtlpExporter(opt =>
{
// If endpoint was not specified, the proper one will be selected according to the protocol.
if (!string.IsNullOrEmpty(endpoint))
{
opt.Endpoint = new Uri(endpoint);
}
opt.Protocol = otlpExportProtocol.Value;
System.Console.WriteLine($"OTLP Exporter is using {opt.Protocol} protocol and endpoint {opt.Endpoint}");
})
.Build();

View File

@ -8,6 +8,7 @@ receivers:
otlp:
protocols:
grpc:
http:
exporters:
logging: