Skip to content

Commit

Permalink
Update OTEL Exporter
Browse files Browse the repository at this point in the history
Add Open Telemetry Console Exporter nuget package
Update documentation
  • Loading branch information
jonsofte committed Mar 24, 2023
1 parent 56b8693 commit 55a2fb6
Show file tree
Hide file tree
Showing 5 changed files with 28 additions and 12 deletions.
10 changes: 8 additions & 2 deletions Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -9,19 +9,23 @@ If a service is running on a host with a public facing IP address that might cha

If an external client which is dependent on the internal service, detects that the service is no longer available, it can get the new IP address from the store, update its internal configuration, and reconnect to the service that is now being exposed on the new IP address.

## Implementation
## Description

* For detecting the current IP address, the service calls the [ipify.org](https://www.ipify.org/) public REST API.
* The previous registered IP address is stored in a [Azure Storage Container Blob](https://azure.microsoft.com/en-us/products/storage/blobs).
* The application authenticates to Azure with an Application Service Principal. The principal has an assigned role that has read/write access to the specified storage container.
* A cron job triggers and runs the service at a fixed interval.
* The current public IP address is compared to the previous registered IP address. If it has changed, the new IP address is persisted to the Blob storage container.
* Open Telemetry is provided from the service. Logs and Traces are being forwarded to an [Open Telemetry Collector](https://opentelemetry.io/docs/collector/). This enables Traces to be monitored in Jaeger, and Logs to be viewed in ElasticSearch.
* The service is implemented with .NET 7.
* A Helm chart is provided for easy installation and configuration on a Kubernetes cluster.

![Architecture](https://user-images.githubusercontent.com/24587666/225579998-6ebf0bd8-d5f9-46d1-9e34-96bf5cfe007a.png)

## Logging and Tracing

* Logs are written to the Console (stdout).
* Tracing is optional, and may be sent to an [Open Telemetry Collector](https://opentelemetry.io/docs/collector/). Forwarding of traces is done by enabeling the feature flag and specifying an URI to an OTLP HttpProtobuf protocol enabled endpoint. See the Configuration Parameters

## Installation and configuration of Azure Resources and Certificate

1. Create a Storage Account in Azure ([Docs](https://learn.microsoft.com/en-us/azure/storage/common/storage-account-create?tabs=azure-cli)). Take note of the Account URI.
Expand Down Expand Up @@ -163,4 +167,6 @@ The following table lists the configurable parameters of the IP Watcher and thei
| `azure.auth.certPassword` | Password for the PFX certificate | `nil` **(Must be provided)** |
| `azure.auth.tentantID` | Azure AD Tenant ID for authenticating the application with Azure AD. In GUID format: `00000000-0000-0000-0000-000000000000` | `nil` **(Must be provided)**|
| `azure.auth.clientID` | Azure AD Client ID for authenticating the application with Azure AD. In GUID format: `00000000-0000-0000-0000-000000000000` | `nil` **(Must be provided)**|
| `otel.enable` | True/False: Enable OTEL exporter for sending Tracing to an OpenTelemetry Collector | `false` |
| `otel.endpoint` | URI to OpenTelemetry Traces Collector. The exporter is using the HttpProtobuf protocol. Example of URI: `http://<service>:4318/v1/traces` | `nil` (Must be provided) |
2 changes: 1 addition & 1 deletion helm/ip-watcher/values.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -25,4 +25,4 @@ azure:

otel:
enable: false
endpoint:
endpoint:
9 changes: 7 additions & 2 deletions src/IPWatcher.ConsoleApp/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,12 @@ static IHostBuilder CreateHostBuilder(string[] args) => Host.CreateDefaultBuilde
{
if (EnableOTEL)
{
builder.AddOtlpExporter(o => o.Endpoint = new Uri(OTELEndoint));
builder.AddOtlpExporter(o =>
{
o.Endpoint = new Uri(OTELEndoint);
o.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf;
}
);
}
builder
Expand Down Expand Up @@ -70,4 +75,4 @@ static bool isOTELEnabled(HostBuilderContext hostBuilderContext)
return false;
}
return (hostBuilderContext.Configuration["ApplicationConfiguration:OTELEnable"]! == "true");
}
}
2 changes: 2 additions & 0 deletions src/IPWatcher.SyncService/IPWatcher.SyncService.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -9,10 +9,12 @@

<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="7.0.1" />
<PackageReference Include="Microsoft.Extensions.Logging" Version="7.0.0" />
<PackageReference Include="ncrontab" Version="3.3.1" />
<PackageReference Include="OpenTelemetry" Version="1.4.0" />
<PackageReference Include="OpenTelemetry.Exporter.OpenTelemetryProtocol" Version="1.4.0" />
<PackageReference Include="OpenTelemetry.Extensions.Hosting" Version="1.4.0" />
<PackageReference Include="OpenTelemetry.Exporter.Console" Version="1.4.0" />
<PackageReference Include="Serilog.Extensions.Hosting" Version="5.0.1" />
<PackageReference Include="Serilog.Settings.Configuration" Version="3.4.0" />
<PackageReference Include="Serilog.Sinks.Console" Version="4.1.0" />
Expand Down
17 changes: 10 additions & 7 deletions src/IPWatcher.SyncService/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -30,24 +30,27 @@
bool EnableOTEL = isOTELEnabled(hostBuilderContext);
string OTELEndoint = hostBuilderContext.Configuration["ApplicationConfiguration:OTELExporterEndpoint"]!;
services.AddOptions();
services.AddOpenTelemetry()
.WithTracing(builder =>
{
if (EnableOTEL)
{
builder.AddOtlpExporter(o => o.Endpoint = new Uri(OTELEndoint));
Console.WriteLine($"OTEL enabled. Sending traces to: {OTELEndoint}");
}
builder
.AddConsoleExporter()
.AddSource("IP Watcher")
.SetResourceBuilder(
ResourceBuilder.CreateDefault()
.AddService(hostBuilderContext.HostingEnvironment.ApplicationName)
);
if (EnableOTEL)
{
builder.AddOtlpExporter(o =>
{
o.Endpoint = new Uri(OTELEndoint);
o.Protocol = OpenTelemetry.Exporter.OtlpExportProtocol.HttpProtobuf;
});
Console.WriteLine($"OTEL enabled. Sending traces to: {OTELEndoint}");
}
});
services.Configure<ApplicationConfiguration>(hostBuilderContext.Configuration.GetSection("ApplicationConfiguration"));
services.Configure<AzureStorageConfiguration>(hostBuilderContext.Configuration.GetSection("AzureStorageConfiguration"));
Expand Down

0 comments on commit 55a2fb6

Please sign in to comment.