Skip to content

Commit

Permalink
initial commit
Browse files Browse the repository at this point in the history
  • Loading branch information
Yun-Ting committed Jun 9, 2022
1 parent 91d7e83 commit 4a15783
Show file tree
Hide file tree
Showing 4 changed files with 138 additions and 0 deletions.
6 changes: 6 additions & 0 deletions OpenTelemetry.sln
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
Expand Down
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>
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()
{

}

}
}
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;
}
}
}
}

0 comments on commit 4a15783

Please sign in to comment.