From 8a542b95c3c42a08b18a522af04cd3ae51ef7d75 Mon Sep 17 00:00:00 2001 From: qinyouzeng Date: Tue, 3 Mar 2026 17:24:08 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0redis=E9=93=BE=E8=B7=AF?= =?UTF-8?q?=E8=AE=B0=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...sultFactory .cs => CustomResultFactory.cs} | 3 -- src/Services/Masa.Dcc.Service/Program.cs | 28 ++++++++++++------- src/Services/Masa.Dcc.Service/_Imports.cs | 5 +++- 3 files changed, 22 insertions(+), 14 deletions(-) rename src/Services/Masa.Dcc.Service/Infrastructure/{CustomResultFactory .cs => CustomResultFactory.cs} (83%) diff --git a/src/Services/Masa.Dcc.Service/Infrastructure/CustomResultFactory .cs b/src/Services/Masa.Dcc.Service/Infrastructure/CustomResultFactory.cs similarity index 83% rename from src/Services/Masa.Dcc.Service/Infrastructure/CustomResultFactory .cs rename to src/Services/Masa.Dcc.Service/Infrastructure/CustomResultFactory.cs index 2782721..cdefc6d 100644 --- a/src/Services/Masa.Dcc.Service/Infrastructure/CustomResultFactory .cs +++ b/src/Services/Masa.Dcc.Service/Infrastructure/CustomResultFactory.cs @@ -1,9 +1,6 @@ // Copyright (c) MASA Stack All rights reserved. // Licensed under the Apache License. See LICENSE.txt in the project root for license information. -using FluentValidation.Results; -using SharpGrip.FluentValidation.AutoValidation.Endpoints.Results; - namespace Masa.Dcc.Service.Admin.Infrastructure; public class CustomResultFactory : IFluentValidationAutoValidationResultFactory diff --git a/src/Services/Masa.Dcc.Service/Program.cs b/src/Services/Masa.Dcc.Service/Program.cs index d796568..59c002f 100644 --- a/src/Services/Masa.Dcc.Service/Program.cs +++ b/src/Services/Masa.Dcc.Service/Program.cs @@ -12,6 +12,7 @@ var dbModel = JsonSerializer.Deserialize(connStr)!; bool isPgsql = string.Equals(dbModel.DbType, "postgresql", StringComparison.CurrentCultureIgnoreCase); var publicConfiguration = builder.Services.GetMasaConfiguration().ConfigurationApi.GetPublic(); +StackExchangeRedisInstrumentation redisInstrumentation = default!; var ossSptions = publicConfiguration.GetSection(DccConstants.OssKey).Get()!; builder.Services.AddObjectStorage(option => option.UseAliyunStorage(options => @@ -27,16 +28,23 @@ }; })); -if (!builder.Environment.IsDevelopment()) +builder.Services.AddObservable(builder.Logging, new MasaObservableOptions { - builder.Services.AddObservable(builder.Logging, () => new MasaObservableOptions + ServiceNameSpace = builder.Environment.EnvironmentName, + ServiceVersion = masaStackConfig.Version, + ServiceName = masaStackConfig.GetServiceId(MasaStackProject.DCC), + ServiceInstanceId = builder.Configuration.GetValue("HOSTNAME")! +}, masaStackConfig.OtlpUrl, true, traceInstrumentConfig: traceBuilder => +{ + traceBuilder.AddRedisInstrumentation(options => { - ServiceNameSpace = builder.Environment.EnvironmentName, - ServiceVersion = masaStackConfig.Version, - ServiceName = masaStackConfig.GetServiceId(MasaStackProject.DCC), - ServiceInstanceId = builder.Configuration.GetValue("HOSTNAME")! - }, () => masaStackConfig.OtlpUrl, true); -} + options.SetVerboseDatabaseStatements = true; + }) + .ConfigureRedisInstrumentation(instrumentation => + { + redisInstrumentation = instrumentation; + }); +}); builder.Services.AddMasaIdentity(options => { @@ -110,7 +118,7 @@ builder.Services.AddMultilevelCache(distributedCacheAction: distributedCacheOptions => { - distributedCacheOptions.UseStackExchangeRedisCache(redisOption); + distributedCacheOptions.UseStackExchangeRedisCache(redisOption, connectConfig: connect => redisInstrumentation.AddConnection(connect)); }, options => { options.SubscribeKeyPrefix = "masa.dcc:"; @@ -118,7 +126,7 @@ }); builder.Services.AddPmClient(masaStackConfig.GetPmServiceDomain()); -builder.Services.AddAuthClient(authServiceBaseAddress: masaStackConfig.GetAuthServiceDomain(), redisOption); +builder.Services.AddAuthClient(authServiceBaseAddress: masaStackConfig.GetAuthServiceDomain(), redisOption, connectConfig: connect => redisInstrumentation.AddConnection(connect)); builder.Services #if DEBUG diff --git a/src/Services/Masa.Dcc.Service/_Imports.cs b/src/Services/Masa.Dcc.Service/_Imports.cs index fb2ecb5..684b082 100644 --- a/src/Services/Masa.Dcc.Service/_Imports.cs +++ b/src/Services/Masa.Dcc.Service/_Imports.cs @@ -7,6 +7,7 @@ global using System.Xml.Linq; global using FluentValidation; global using FluentValidation.Resources; +global using FluentValidation.Results; global using Masa.BuildingBlocks.Authentication.Identity; global using Masa.BuildingBlocks.Caching; global using Masa.BuildingBlocks.Configuration; @@ -46,9 +47,11 @@ global using Masa.Dcc.Service.Admin.Infrastructure; global using Masa.Dcc.Service.Admin.Infrastructure.Middleware; global using Microsoft.AspNetCore.Authentication.JwtBearer; -global using Microsoft.AspNetCore.Authorization; global using Microsoft.AspNetCore.Mvc; global using Microsoft.EntityFrameworkCore; global using Microsoft.IdentityModel.Tokens; global using Microsoft.OpenApi.Models; +global using OpenTelemetry.Instrumentation.StackExchangeRedis; +global using OpenTelemetry.Trace; global using SharpGrip.FluentValidation.AutoValidation.Endpoints.Extensions; +global using SharpGrip.FluentValidation.AutoValidation.Endpoints.Results;