Skip to content

Commit

Permalink
Span interface definition, Span model definition added (#25)
Browse files Browse the repository at this point in the history
1. Changes within the Mocha.Storage MysqlSpanWrite,
EntityFrameworkSpanWrite MySQLSpanReader EntityFrameworkSpanReader
2. Changes within the Mocha.Core.Storage ISpanWriter, ISpanWrite
3. Add MochaContext definition
4. #7
  • Loading branch information
KawhiWei authored Oct 23, 2023
1 parent be64132 commit a17af3f
Show file tree
Hide file tree
Showing 14 changed files with 180 additions and 16 deletions.
2 changes: 1 addition & 1 deletion .editorconfig
Original file line number Diff line number Diff line change
Expand Up @@ -73,4 +73,4 @@ dotnet_naming_style.camel_case_underscore_style.required_prefix = _
dotnet_naming_style.camel_case_underscore_style.capitalization = camel_case

# file header
file_header_template = Licensed to the.NET Core Community under one or more agreements.\nThe.NET Core Community licenses this file to you under the MIT license.
file_header_template = Licensed to the .NET Core Community under one or more agreements.\nThe .NET Core Community licenses this file to you under the MIT license.
19 changes: 19 additions & 0 deletions src/Mocha.Core/Enums/SpanKind.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

namespace Mocha.Core.Enums;

public enum SpanKind
{
Unspecified = 0,

Client = 1,

Server = 2,

Internal = 3,

Producer = 4,

Consumer = 5
}
4 changes: 4 additions & 0 deletions src/Mocha.Core/Mocha.Core.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -7,4 +7,8 @@
<EnforceCodeStyleInBuild>true</EnforceCodeStyleInBuild>
</PropertyGroup>

<ItemGroup>
<ProjectReference Include="..\Mocha.Protocol.Generated\Mocha.Protocol.Generated.csproj" />
</ItemGroup>

</Project>
8 changes: 4 additions & 4 deletions src/Mocha.Core/Storage/ISpanReader.cs
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

using Mocha.Core.Storage.Query;

namespace Mocha.Core.Storage;

/// <summary>
///
/// </summary>
public interface ISpanReader
{
Task<IEnumerable<string>> FindTraceIdListAsync(TraceReadQuery query);

Task FindTraceList(string serviceName);
Task FindSpanListByTraceIdAsync(string traceId);
}
6 changes: 3 additions & 3 deletions src/Mocha.Core/Storage/ISpanWriter.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

using OpenTelemetry.Proto.Trace.V1;

namespace Mocha.Core.Storage;

public interface ISpanWriter
{
Task<bool> WriterAsync();

bool Writer();
Task WriteAsync(IEnumerable<Span> spans);
}
19 changes: 19 additions & 0 deletions src/Mocha.Core/Storage/Query/TraceReadQuery.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

using System.Collections;

namespace Mocha.Core.Storage.Query;

public class TraceReadQuery
{
public string? ServiceName { get; set; }

public IDictionary<string, string>? SpanAttributes { get; set; }

public long? StartTimeStamp { get; set; }

public long? EndTimeStamp { get; set; }

public string? SpanName { get; set; }
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,18 @@
// The .NET Core Community licenses this file to you under the MIT license.

using Mocha.Core.Storage;
using Mocha.Core.Storage.Query;

namespace Mocha.Storage.Mysql;
namespace Mocha.Storage.EntityFrameworkStorage;

public class MySqlSpanWriter : ISpanWriter
public class EntityFrameworkSpanReader : ISpanReader
{
public Task<bool> WriterAsync()
public Task<IEnumerable<string>> FindTraceIdListAsync(TraceReadQuery query)
{
throw new NotImplementedException();
}

public bool Writer()
public Task FindSpanListByTraceIdAsync(string traceId)
{
throw new NotImplementedException();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@

using Mocha.Core.Storage;

namespace Mocha.Storage.Mysql;
namespace Mocha.Storage.EntityFrameworkStorage;

public class MySqlSpanReader : ISpanReader
public class EntityFrameworkSpanWriter : ISpanWriter
{
public Task FindTraceList(string serviceName)
public Task WriteAsync(IEnumerable<OpenTelemetry.Proto.Trace.V1.Span> spans)
{
throw new NotImplementedException();
}
Expand Down
41 changes: 41 additions & 0 deletions src/Mocha.Storage/EntityFrameworkStorage/Trace/Span.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

using Mocha.Core.Enums;

namespace Mocha.Storage.EntityFrameworkStorage.Trace;

public class Span
{
public string TraceId { get; set; } = string.Empty;

public string SpanId { get; set; } = string.Empty;

public string SpanName { get; set; } = string.Empty;

public string ParentSpanId { get; set; } = string.Empty;

public string ServiceName { get; set; } = string.Empty;

public long StartTime { get; set; }

public long EndTime { get; set; }

public double Duration { get; set; }

public int StatusCode { get; set; }

public string? StatusMessage { get; set; } = string.Empty;

public SpanKind SpanKind { get; set; }

public uint TraceFlags { get; set; }

public string? TraceState { get; set; }

public IEnumerable<SpanLink> SpanLinks { get; set; } = Enumerable.Empty<SpanLink>();

public IEnumerable<SpanAttribute> SpanAttributes { get; set; } = Enumerable.Empty<SpanAttribute>();

public IEnumerable<SpanEvent> SpanEvents { get; set; } = Enumerable.Empty<SpanEvent>();
}
19 changes: 19 additions & 0 deletions src/Mocha.Storage/EntityFrameworkStorage/Trace/SpanAttribute.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

namespace Mocha.Storage.EntityFrameworkStorage.Trace;

public class SpanAttribute
{
public string AttributeKey { get; set; } = string.Empty;

public string AttributeValue { get; set; } = string.Empty;

public long TimeBucket { get; set; }

public string TraceId { get; set; } = string.Empty;

public string SpanId { get; set; } = string.Empty;

public Span Span { get; set; } = default!;
}
16 changes: 16 additions & 0 deletions src/Mocha.Storage/EntityFrameworkStorage/Trace/SpanEvent.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.


namespace Mocha.Storage.EntityFrameworkStorage.Trace;

public class SpanEvent
{
public string TraceId { get; set; } = string.Empty;

public long TimeBucket { get; set; }

public string EventName { get; set; } = string.Empty;

public Span Span { get; set; } = default!;
}
19 changes: 19 additions & 0 deletions src/Mocha.Storage/EntityFrameworkStorage/Trace/SpanLink.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

namespace Mocha.Storage.EntityFrameworkStorage.Trace;

public class SpanLink
{
public string TraceId { get; private set; } = string.Empty;

public string SpanId { get; private set; } = string.Empty;

public string LinkedSpanId { get; private set; } = string.Empty;

public string TraceState { get; private set; } = string.Empty;

public bool Flags { get; private set; }

public Span Span { get; set; } = default!;
}
6 changes: 5 additions & 1 deletion src/Mocha.Storage/Mocha.Storage.csproj
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
<Project Sdk="Microsoft.NET.Sdk">

<PropertyGroup>
<TargetFramework>net7.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
Expand All @@ -9,4 +8,9 @@
<ItemGroup>
<ProjectReference Include="..\Mocha.Core\Mocha.Core.csproj" />
</ItemGroup>
<ItemGroup>
<PackageReference Include="EFCore.NamingConventions" Version="7.0.2" />
<PackageReference Include="Microsoft.EntityFrameworkCore" Version="7.0.12" />
<PackageReference Include="Pomelo.EntityFrameworkCore.MySql" Version="7.0.0" />
</ItemGroup>
</Project>
22 changes: 22 additions & 0 deletions src/Mocha.Storage/MochaContext.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
// Licensed to the .NET Core Community under one or more agreements.
// The .NET Core Community licenses this file to you under the MIT license.

using Microsoft.EntityFrameworkCore;
using Mocha.Storage.EntityFrameworkStorage.Trace;

namespace Mocha.Storage;

public class MochaContext : DbContext
{
public MochaContext(DbContextOptions options) : base(options)
{
}

public DbSet<SpanAttribute> SpanAttributes => Set<SpanAttribute>();

public DbSet<SpanEvent> SpanEvents => Set<SpanEvent>();

public DbSet<SpanLink> SpanLinks => Set<SpanLink>();

public DbSet<Span> Spans => Set<Span>();
}

0 comments on commit a17af3f

Please sign in to comment.