diff --git a/OpenTelemetry.sln b/OpenTelemetry.sln index e74cd272481..277897ebacd 100644 --- a/OpenTelemetry.sln +++ b/OpenTelemetry.sln @@ -236,6 +236,8 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "OpenTelemetry.Extensions.Pr EndProject Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "correlation", "docs\logs\correlation\correlation.csproj", "{9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}" EndProject +Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "OpenTelemetry.Exporter.Prometheus.HTTP.Server", "src\OpenTelemetry.Exporter.Prometheus.HTTP.Server\OpenTelemetry.Exporter.Prometheus.HTTP.Server.csproj", "{D6F23649-C3F8-4477-8854-0B37C6FE28E9}" +EndProject Global GlobalSection(SolutionConfigurationPlatforms) = preSolution Debug|Any CPU = Debug|Any CPU @@ -486,6 +488,10 @@ Global {9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}.Debug|Any CPU.Build.0 = Debug|Any CPU {9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}.Release|Any CPU.ActiveCfg = Release|Any CPU {9A07D215-90AC-4BAF-BCDB-73D74FD3A5C5}.Release|Any CPU.Build.0 = Release|Any CPU + {D6F23649-C3F8-4477-8854-0B37C6FE28E9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU + {D6F23649-C3F8-4477-8854-0B37C6FE28E9}.Debug|Any CPU.Build.0 = Debug|Any CPU + {D6F23649-C3F8-4477-8854-0B37C6FE28E9}.Release|Any CPU.ActiveCfg = Release|Any CPU + {D6F23649-C3F8-4477-8854-0B37C6FE28E9}.Release|Any CPU.Build.0 = Release|Any CPU EndGlobalSection GlobalSection(SolutionProperties) = preSolution HideSolutionNode = FALSE diff --git a/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/OpenTelemetry.Exporter.Prometheus.HTTP.Server.csproj b/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/OpenTelemetry.Exporter.Prometheus.HTTP.Server.csproj new file mode 100644 index 00000000000..d02f6fc30e1 --- /dev/null +++ b/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/OpenTelemetry.Exporter.Prometheus.HTTP.Server.csproj @@ -0,0 +1,34 @@ + + + + + netcoreapp3.1;net462 + Prometheus exporter for OpenTelemetry .NET + $(PackageTags);prometheus;metrics + core- + + + + $(NoWarn),1591 + + + + + false + + + + + + + + + + + + + + + + \ No newline at end of file diff --git a/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServer.cs b/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServer.cs new file mode 100644 index 00000000000..2774f348524 --- /dev/null +++ b/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServer.cs @@ -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() + { + + } + + } +} diff --git a/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServerOptions.cs b/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServerOptions.cs new file mode 100644 index 00000000000..e88e0380c38 --- /dev/null +++ b/src/OpenTelemetry.Exporter.Prometheus.HTTP.Server/PrometheusExporterHttpServerOptions.cs @@ -0,0 +1,70 @@ +// +// 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. +// + +using System; +using System.Collections.Generic; +using OpenTelemetry.Internal; + +namespace OpenTelemetry.Exporter +{ + /// + /// options. + /// + public class PrometheusExporterHttpServerOptions + { + private IReadOnlyCollection httpListenerPrefixes = new string[] { "http://localhost:9464/" }; + +#if NETCOREAPP3_1_OR_GREATER + /// + /// Gets or sets a value indicating whether or not an http listener + /// should be started. Default value: False. + /// + public bool StartHttpListener { get; set; } +#else + /// + /// Gets or sets a value indicating whether or not an http listener + /// should be started. Default value: True. + /// + public bool StartHttpListener { get; set; } = true; +#endif + + /// + /// Gets or sets the prefixes to use for the http listener. Default + /// value: http://localhost:9464/. + /// + public IReadOnlyCollection 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; + } + } + } +}