96 lines
3.1 KiB
C#
96 lines
3.1 KiB
C#
using System.Text.Json;
|
|
using Omika.Core.Observability.External;
|
|
using Omika.Core.Observability.Outbox;
|
|
using Omika.Diagnostics.Models;
|
|
|
|
namespace Omika.Diagnostics.Tests.Fakes;
|
|
|
|
/// <summary>Fabriques d'événements et d'enregistrements JSONL pour les tests.</summary>
|
|
public static class DiagnosticTestData
|
|
{
|
|
private static readonly JsonSerializerOptions JsonOptions = new(JsonSerializerDefaults.Web);
|
|
|
|
public static RemoteDiagnosticRecord Record(
|
|
Guid eventId,
|
|
string eventCode = "TEST",
|
|
DateTimeOffset? timestamp = null,
|
|
Guid? traceId = null,
|
|
Guid? sessionId = null,
|
|
Guid? operationId = null,
|
|
string? component = null,
|
|
string level = "Info",
|
|
string priority = "P2",
|
|
string? errorCode = null,
|
|
long? durationMs = null,
|
|
Dictionary<string, object?>? metadata = null,
|
|
string? actorKey = null,
|
|
int? actorKeyVersion = null,
|
|
string? clientCode = null,
|
|
string? serverInstance = null,
|
|
string? environment = null)
|
|
{
|
|
DateTimeOffset ts = timestamp ?? DateTimeOffset.UtcNow;
|
|
return new RemoteDiagnosticRecord
|
|
{
|
|
ReceivedAtUtc = ts,
|
|
BatchId = Guid.NewGuid(),
|
|
IngestionTraceId = Guid.NewGuid().ToString("D"),
|
|
ActorKey = actorKey,
|
|
ActorKeyVersion = actorKeyVersion,
|
|
ClientCode = clientCode,
|
|
ServerInstance = serverInstance,
|
|
Environment = environment,
|
|
Event = new DiagnosticEventDto
|
|
{
|
|
EventId = eventId,
|
|
EventCode = eventCode,
|
|
TimestampUtc = ts,
|
|
Level = level,
|
|
Priority = priority,
|
|
Component = component,
|
|
TraceId = traceId,
|
|
SessionId = sessionId,
|
|
OperationId = operationId,
|
|
ErrorCode = errorCode,
|
|
DurationMs = durationMs,
|
|
Metadata = metadata
|
|
}
|
|
};
|
|
}
|
|
|
|
public static DiagnosticEventRecord Event(
|
|
Guid eventId,
|
|
string eventCode = "TEST",
|
|
DateTimeOffset? timestamp = null,
|
|
Guid? traceId = null,
|
|
Guid? operationId = null,
|
|
string? component = null,
|
|
string level = "Info",
|
|
string? errorCode = null,
|
|
long? durationMs = null,
|
|
string? actorKey = null,
|
|
int? actorKeyVersion = null)
|
|
{
|
|
return new DiagnosticEventRecord
|
|
{
|
|
EventId = eventId,
|
|
EventCode = eventCode,
|
|
TimestampUtc = timestamp ?? DateTimeOffset.UtcNow,
|
|
TraceId = traceId,
|
|
OperationId = operationId,
|
|
Component = component,
|
|
Level = level,
|
|
Priority = "P2",
|
|
ErrorCode = errorCode,
|
|
DurationMs = durationMs,
|
|
ActorKey = actorKey,
|
|
ActorKeyVersion = actorKeyVersion,
|
|
Source = DiagnosticSources.Mobile,
|
|
IngestedAtUtc = DateTimeOffset.UtcNow
|
|
};
|
|
}
|
|
|
|
public static string SerializeLine(RemoteDiagnosticRecord record) =>
|
|
JsonSerializer.Serialize(record, JsonOptions);
|
|
}
|