Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improvements to the OTLP trace example #3141

Merged
merged 2 commits into from
Apr 6, 2022
Merged
Show file tree
Hide file tree
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Next Next commit
NIT: make cli commads work with copy and paste
Better defaults and update collector and config

Remove test added by mistake on last commit
  • Loading branch information
pjanotti committed Apr 5, 2022
commit 2d16cf37a4bca2b79f508b9123ba46e69be07a7e
23 changes: 13 additions & 10 deletions examples/Console/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -27,18 +27,21 @@ public class Program
/// 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\).
/// </summary>
pjanotti marked this conversation as resolved.
Show resolved Hide resolved
/// <param name="args">Arguments from command line.</param>
public static void Main(string[] args)
{
Expand Down Expand Up @@ -153,7 +156,7 @@ internal class OpenTracingShimOptions
[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")]
Expand Down
11 changes: 8 additions & 3 deletions examples/Console/TestOtlpExporter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -34,10 +34,10 @@ internal static object Run(string endpoint, string protocol)
* 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
cijothomas marked this conversation as resolved.
Show resolved Hide resolved
*
* - 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:
Expand Down Expand Up @@ -74,7 +74,12 @@ private static object RunWithActivitySource(string endpoint, string protocol)
.SetResourceBuilder(ResourceBuilder.CreateDefault().AddService("otlp-test"))
.AddOtlpExporter(opt =>
{
opt.Endpoint = new Uri(endpoint);
// If endpoint was not specified, the proper one will be selected according to the protocol.
pjanotti marked this conversation as resolved.
Show resolved Hide resolved
if (!string.IsNullOrEmpty(endpoint))
{
opt.Endpoint = new Uri(endpoint);
}

opt.Protocol = otlpExportProtocol.Value;
})
.Build();
Expand Down
1 change: 1 addition & 0 deletions examples/Console/otlp-collector-example/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ receivers:
otlp:
protocols:
grpc:
http:

exporters:
logging:
Expand Down