forked from open-telemetry/opentelemetry-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 1
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
4 changed files
with
138 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
34 changes: 34 additions & 0 deletions
34
...etry.Exporter.Prometheus.HTTP.Server/OpenTelemetry.Exporter.Prometheus.HTTP.Server.csproj
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,34 @@ | ||
<Project Sdk="Microsoft.NET.Sdk"> | ||
|
||
<PropertyGroup> | ||
<!-- OmniSharp/VS Code requires TargetFrameworks to be in descending order for IntelliSense and analysis. --> | ||
<TargetFrameworks>netcoreapp3.1;net462</TargetFrameworks> | ||
<Description>Prometheus exporter for OpenTelemetry .NET</Description> | ||
<PackageTags>$(PackageTags);prometheus;metrics</PackageTags> | ||
<MinVerTagPrefix>core-</MinVerTagPrefix> | ||
</PropertyGroup> | ||
|
||
<PropertyGroup> | ||
<NoWarn>$(NoWarn),1591</NoWarn> | ||
</PropertyGroup> | ||
|
||
<!--Do not run ApiCompat as this package has never released a stable version. | ||
Remove this property once we have released a stable version.--> | ||
<PropertyGroup> | ||
<RunApiCompat>false</RunApiCompat> | ||
</PropertyGroup> | ||
|
||
<ItemGroup> | ||
<ProjectReference Include="$(RepoRoot)\src\OpenTelemetry\OpenTelemetry.csproj" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup> | ||
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\ExceptionExtensions.cs" Link="Includes\ExceptionExtensions.cs" /> | ||
<Compile Include="$(RepoRoot)\src\OpenTelemetry.Api\Internal\Guard.cs" Link="Includes\Guard.cs" /> | ||
</ItemGroup> | ||
|
||
<ItemGroup Condition="'$(TargetFramework)' == 'netcoreapp3.1'"> | ||
<FrameworkReference Include="Microsoft.AspNetCore.App" /> | ||
</ItemGroup> | ||
|
||
</Project> |
28 changes: 28 additions & 0 deletions
28
src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServer.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,28 @@ | ||
using System; | ||
using System.Net; | ||
using System.Threading; | ||
|
||
namespace OpenTelemetry.Exporter.Prometheus.HTTP.Server | ||
{ | ||
internal class PrometheusExporterHttpServer | ||
{ | ||
private readonly HttpListener listener = new(); | ||
private readonly object syncObject = new(); | ||
|
||
private CancellationTokenSource tokenSource; | ||
|
||
public PrometheusExporterHttpServer(PrometheusExporterHttpServerOptions options) | ||
{ | ||
if ((options.HttpListenerPrefixes?.Count ?? 0) <= 0) | ||
{ | ||
throw new ArgumentException("No HttpListenerPrefixes were specified on PrometheusExporterHttpServerOptions."); | ||
} | ||
} | ||
|
||
public void Start() | ||
{ | ||
|
||
} | ||
|
||
} | ||
} |
70 changes: 70 additions & 0 deletions
70
src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServerOptions.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,70 @@ | ||
// <copyright file="PrometheusExporterHttpServerOptions.cs" company="OpenTelemetry Authors"> | ||
// Copyright The OpenTelemetry Authors | ||
// | ||
// Licensed under the Apache License, Version 2.0 (the "License"); | ||
// you may not use this file except in compliance with the License. | ||
// You may obtain a copy of the License at | ||
// | ||
// http://www.apache.org/licenses/LICENSE-2.0 | ||
// | ||
// Unless required by applicable law or agreed to in writing, software | ||
// distributed under the License is distributed on an "AS IS" BASIS, | ||
// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. | ||
// See the License for the specific language governing permissions and | ||
// limitations under the License. | ||
// </copyright> | ||
|
||
using System; | ||
using System.Collections.Generic; | ||
using OpenTelemetry.Internal; | ||
|
||
namespace OpenTelemetry.Exporter | ||
{ | ||
/// <summary> | ||
/// <see cref="PrometheusExporterHttpServer"/> options. | ||
/// </summary> | ||
public class PrometheusExporterHttpServerOptions | ||
{ | ||
private IReadOnlyCollection<string> httpListenerPrefixes = new string[] { "http://localhost:9464/" }; | ||
|
||
#if NETCOREAPP3_1_OR_GREATER | ||
/// <summary> | ||
/// Gets or sets a value indicating whether or not an http listener | ||
/// should be started. Default value: False. | ||
/// </summary> | ||
public bool StartHttpListener { get; set; } | ||
#else | ||
/// <summary> | ||
/// Gets or sets a value indicating whether or not an http listener | ||
/// should be started. Default value: True. | ||
/// </summary> | ||
public bool StartHttpListener { get; set; } = true; | ||
#endif | ||
|
||
/// <summary> | ||
/// Gets or sets the prefixes to use for the http listener. Default | ||
/// value: http://localhost:9464/. | ||
/// </summary> | ||
public IReadOnlyCollection<string> HttpListenerPrefixes | ||
{ | ||
get => this.httpListenerPrefixes; | ||
set | ||
{ | ||
Guard.ThrowIfNull(value); | ||
|
||
foreach (string inputUri in value) | ||
{ | ||
if (!(Uri.TryCreate(inputUri, UriKind.Absolute, out var uri) && | ||
(uri.Scheme == Uri.UriSchemeHttp || uri.Scheme == Uri.UriSchemeHttps))) | ||
{ | ||
throw new ArgumentException( | ||
"Prometheus server path should be a valid URI with http/https scheme.", | ||
nameof(this.httpListenerPrefixes)); | ||
} | ||
} | ||
|
||
this.httpListenerPrefixes = value; | ||
} | ||
} | ||
} | ||
} |