Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
CAP
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
tsai
CAP
Commits
e20d9a37
Commit
e20d9a37
authored
Apr 03, 2019
by
彭伟
Committed by
Lemon
Apr 03, 2019
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add general host (#182)
parent
8d85b304
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
364 additions
and
3 deletions
+364
-3
Program.cs
sample/SkyApm.Sample.GeneralHost/Program.cs
+19
-0
SkyApm.Sample.GeneralHost.csproj
...kyApm.Sample.GeneralHost/SkyApm.Sample.GeneralHost.csproj
+18
-0
Worker.cs
sample/SkyApm.Sample.GeneralHost/Worker.cs
+34
-0
skyapm.json
sample/SkyApm.Sample.GeneralHost/skyapm.json
+29
-0
skyapm-dotnet.sln
skyapm-dotnet.sln
+17
-3
HostBuilderExtensions.cs
...Apm.Agent.GeneralHost/Extensions/HostBuilderExtensions.cs
+28
-0
ServiceCollectionExtensions.cs
...ent.GeneralHost/Extensions/ServiceCollectionExtensions.cs
+112
-0
HostingEnvironmentProvider.cs
src/SkyApm.Agent.GeneralHost/HostingEnvironmentProvider.cs
+32
-0
InstrumentationHostedService.cs
src/SkyApm.Agent.GeneralHost/InstrumentationHostedService.cs
+44
-0
SkyApm.Agent.GeneralHost.csproj
src/SkyApm.Agent.GeneralHost/SkyApm.Agent.GeneralHost.csproj
+31
-0
No files found.
sample/SkyApm.Sample.GeneralHost/Program.cs
0 → 100644
View file @
e20d9a37
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Hosting
;
using
SkyApm.Agent.GeneralHost
;
namespace
SkyApm.Sample.GeneralHost
{
public
class
Program
{
public
static
void
Main
(
string
[]
args
)
{
CreateHostBuilder
(
args
).
Build
().
Run
();
}
public
static
IHostBuilder
CreateHostBuilder
(
string
[]
args
)
=>
new
HostBuilder
()
.
ConfigureServices
(
services
=>
services
.
AddHostedService
<
Worker
>())
.
AddSkyAPM
();
}
}
sample/SkyApm.Sample.GeneralHost/SkyApm.Sample.GeneralHost.csproj
0 → 100644
View file @
e20d9a37
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp2.1</TargetFramework>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<Content Include="skyapm.json">
<CopyToOutputDirectory>Always</CopyToOutputDirectory>
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
</Content>
<PackageReference Include="Microsoft.Extensions.Hosting" Version="2.1.1" />
<ProjectReference Include="..\..\src\SkyApm.Agent.GeneralHost\SkyApm.Agent.GeneralHost.csproj" />
</ItemGroup>
</Project>
sample/SkyApm.Sample.GeneralHost/Worker.cs
0 → 100644
View file @
e20d9a37
using
Microsoft.Extensions.Hosting
;
using
SkyApm.Tracing
;
using
SkyApm.Tracing.Segments
;
using
System
;
using
System.Collections.Generic
;
using
System.Threading
;
using
System.Threading.Tasks
;
namespace
SkyApm.Sample.GeneralHost
{
public
class
Worker
:
BackgroundService
{
private
readonly
ITracingContext
_tracingContext
;
public
Worker
(
ITracingContext
tracingContext
)
{
_tracingContext
=
tracingContext
;
}
protected
override
async
Task
ExecuteAsync
(
CancellationToken
stoppingToken
)
{
while
(!
stoppingToken
.
IsCancellationRequested
)
{
var
context
=
_tracingContext
.
CreateEntrySegmentContext
(
nameof
(
ExecuteAsync
),
new
TextCarrierHeaderCollection
(
new
Dictionary
<
string
,
string
>()));
await
Task
.
Delay
(
1000
,
stoppingToken
);
context
.
Span
.
AddLog
(
LogEvent
.
Message
(
$"Worker running at:
{
DateTime
.
Now
}
"
));
_tracingContext
.
Release
(
context
);
}
}
}
}
sample/SkyApm.Sample.GeneralHost/skyapm.json
0 → 100644
View file @
e20d9a37
{
"SkyWalking"
:
{
"ServiceName"
:
"general-host-sample"
,
"Namespace"
:
""
,
"HeaderVersions"
:
[
"sw6"
],
"Sampling"
:
{
"SamplePer3Secs"
:
-1
,
"Percentage"
:
-1.0
},
"Logging"
:
{
"Level"
:
"Information"
,
"FilePath"
:
"logs/skyapm-{Date}.log"
},
"Transport"
:
{
"Interval"
:
3000
,
"ProtocolVersion"
:
"v6"
,
"QueueSize"
:
30000
,
"BatchSize"
:
3000
,
"gRPC"
:
{
"Servers"
:
"localhost:11800"
,
"Timeout"
:
100000
,
"ConnectTimeout"
:
100000
,
"ReportTimeout"
:
600000
}
}
}
}
\ No newline at end of file
skyapm-dotnet.sln
View file @
e20d9a37
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio
15
VisualStudioVersion = 1
5.0.27130.2024
# Visual Studio
Version 16
VisualStudioVersion = 1
6.0.28729.10
MinimumVisualStudioVersion = 10.0.40219.1
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "src", "src", "{05BF0D4E-C824-4EC8-8330-36C1FC49910E}"
EndProject
...
...
@@ -82,7 +82,11 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.DotNet.CLI", "src\Sk
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Diagnostics.SmartSql", "src\SkyApm.Diagnostics.SmartSql\SkyApm.Diagnostics.SmartSql.csproj", "{B43160C8-C9E3-43F6-83E9-A9A45B32F022}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyApm.Sample.SmartSql", "sample\SkyApm.Sample.SmartSql\SkyApm.Sample.SmartSql.csproj", "{8E2B336B-8138-4179-A754-A1D0C0471654}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.SmartSql", "sample\SkyApm.Sample.SmartSql\SkyApm.Sample.SmartSql.csproj", "{8E2B336B-8138-4179-A754-A1D0C0471654}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Agent.GeneralHost", "src\SkyApm.Agent.GeneralHost\SkyApm.Agent.GeneralHost.csproj", "{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "SkyApm.Sample.GeneralHost", "sample\SkyApm.Sample.GeneralHost\SkyApm.Sample.GeneralHost.csproj", "{477D705E-576B-46C8-8F1E-9A86EDAE9D86}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
...
...
@@ -182,6 +186,14 @@ Global
{8E2B336B-8138-4179-A754-A1D0C0471654}.Debug|Any CPU.Build.0 = Debug|Any CPU
{8E2B336B-8138-4179-A754-A1D0C0471654}.Release|Any CPU.ActiveCfg = Release|Any CPU
{8E2B336B-8138-4179-A754-A1D0C0471654}.Release|Any CPU.Build.0 = Release|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Debug|Any CPU.Build.0 = Debug|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Release|Any CPU.ActiveCfg = Release|Any CPU
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58}.Release|Any CPU.Build.0 = Release|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Debug|Any CPU.Build.0 = Debug|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Release|Any CPU.ActiveCfg = Release|Any CPU
{477D705E-576B-46C8-8F1E-9A86EDAE9D86}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -218,6 +230,8 @@ Global
{E909EEF5-5EBF-43F3-AB4A-6B2FB56EF89B} = {1B0865AF-369E-493C-AA6F-C56D3E520A22}
{B43160C8-C9E3-43F6-83E9-A9A45B32F022} = {B5E677CF-2920-4B0A-A056-E73F6B2CF2BC}
{8E2B336B-8138-4179-A754-A1D0C0471654} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
{4C1CF0E7-4CD3-4731-9A56-E033D5216D58} = {EF6194B2-9ACB-49B9-8049-DD6AFAEB0399}
{477D705E-576B-46C8-8F1E-9A86EDAE9D86} = {844CEACD-4C85-4B15-9E2B-892B01FDA4BB}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
...
...
src/SkyApm.Agent.GeneralHost/Extensions/HostBuilderExtensions.cs
0 → 100644
View file @
e20d9a37
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You 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
Microsoft.Extensions.Hosting
;
namespace
SkyApm.Agent.GeneralHost
{
public
static
class
HostBuilderExtensions
{
public
static
IHostBuilder
AddSkyAPM
(
this
IHostBuilder
builder
)
=>
builder
.
ConfigureServices
((
context
,
services
)
=>
services
.
AddSkyAPMCore
());
}
}
\ No newline at end of file
src/SkyApm.Agent.GeneralHost/Extensions/ServiceCollectionExtensions.cs
0 → 100644
View file @
e20d9a37
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You 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
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Hosting
;
using
SkyApm.Config
;
using
SkyApm.Diagnostics
;
using
SkyApm.Diagnostics.EntityFrameworkCore
;
using
SkyApm.Diagnostics.HttpClient
;
using
SkyApm.Diagnostics.SqlClient
;
using
SkyApm.Logging
;
using
SkyApm.Sampling
;
using
SkyApm.Service
;
using
SkyApm.Tracing
;
using
SkyApm.Transport
;
using
SkyApm.Transport.Grpc
;
using
SkyApm.Transport.Grpc.V5
;
using
SkyApm.Transport.Grpc.V6
;
using
SkyApm.Utilities.Configuration
;
using
SkyApm.Utilities.DependencyInjection
;
using
SkyApm.Utilities.Logging
;
using
System
;
namespace
SkyApm.Agent.GeneralHost
{
internal
static
class
ServiceCollectionExtensions
{
internal
static
IServiceCollection
AddSkyAPMCore
(
this
IServiceCollection
services
)
{
if
(
services
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
services
));
}
services
.
AddSingleton
<
ISegmentDispatcher
,
AsyncQueueSegmentDispatcher
>();
services
.
AddSingleton
<
IExecutionService
,
RegisterService
>();
services
.
AddSingleton
<
IExecutionService
,
PingService
>();
services
.
AddSingleton
<
IExecutionService
,
ServiceDiscoveryV5Service
>();
services
.
AddSingleton
<
IExecutionService
,
SegmentReportService
>();
services
.
AddSingleton
<
IInstrumentStartup
,
InstrumentStartup
>();
services
.
AddSingleton
<
IRuntimeEnvironment
>(
RuntimeEnvironment
.
Instance
);
services
.
AddSingleton
<
TracingDiagnosticProcessorObserver
>();
services
.
AddSingleton
<
IConfigAccessor
,
ConfigAccessor
>();
services
.
AddSingleton
<
IConfigurationFactory
,
ConfigurationFactory
>();
services
.
AddSingleton
<
IHostedService
,
InstrumentationHostedService
>();
services
.
AddSingleton
<
IEnvironmentProvider
,
HostingEnvironmentProvider
>();
services
.
AddTracing
().
AddSampling
().
AddGrpcTransport
().
AddLogging
();
services
.
AddSkyApmExtensions
().
AddHttpClient
().
AddSqlClient
()
.
AddEntityFrameworkCore
(
c
=>
c
.
AddPomeloMysql
().
AddNpgsql
().
AddSqlite
());
return
services
;
}
private
static
IServiceCollection
AddTracing
(
this
IServiceCollection
services
)
{
services
.
AddSingleton
<
ITracingContext
,
Tracing
.
TracingContext
>();
services
.
AddSingleton
<
ICarrierPropagator
,
CarrierPropagator
>();
services
.
AddSingleton
<
ICarrierFormatter
,
Sw3CarrierFormatter
>();
services
.
AddSingleton
<
ICarrierFormatter
,
Sw6CarrierFormatter
>();
services
.
AddSingleton
<
ISegmentContextFactory
,
SegmentContextFactory
>();
services
.
AddSingleton
<
IEntrySegmentContextAccessor
,
EntrySegmentContextAccessor
>();
services
.
AddSingleton
<
ILocalSegmentContextAccessor
,
LocalSegmentContextAccessor
>();
services
.
AddSingleton
<
IExitSegmentContextAccessor
,
ExitSegmentContextAccessor
>();
services
.
AddSingleton
<
ISamplerChainBuilder
,
SamplerChainBuilder
>();
services
.
AddSingleton
<
IUniqueIdGenerator
,
UniqueIdGenerator
>();
services
.
AddSingleton
<
IUniqueIdParser
,
UniqueIdParser
>();
services
.
AddSingleton
<
ISegmentContextMapper
,
SegmentContextMapper
>();
services
.
AddSingleton
<
IBase64Formatter
,
Base64Formatter
>();
return
services
;
}
private
static
IServiceCollection
AddSampling
(
this
IServiceCollection
services
)
{
services
.
AddSingleton
<
SimpleCountSamplingInterceptor
>();
services
.
AddSingleton
<
ISamplingInterceptor
>(
p
=>
p
.
GetService
<
SimpleCountSamplingInterceptor
>());
services
.
AddSingleton
<
IExecutionService
>(
p
=>
p
.
GetService
<
SimpleCountSamplingInterceptor
>());
services
.
AddSingleton
<
ISamplingInterceptor
,
RandomSamplingInterceptor
>();
return
services
;
}
private
static
IServiceCollection
AddGrpcTransport
(
this
IServiceCollection
services
)
{
services
.
AddSingleton
<
ISkyApmClientV5
,
SkyApmClientV5
>();
services
.
AddSingleton
<
ISegmentReporter
,
SegmentReporter
>();
services
.
AddSingleton
<
ConnectionManager
>();
services
.
AddSingleton
<
IPingCaller
,
PingCaller
>();
services
.
AddSingleton
<
IServiceRegister
,
ServiceRegister
>();
services
.
AddSingleton
<
IExecutionService
,
ConnectService
>();
return
services
;
}
private
static
IServiceCollection
AddLogging
(
this
IServiceCollection
services
)
{
services
.
AddSingleton
<
ILoggerFactory
,
DefaultLoggerFactory
>();
return
services
;
}
}
}
\ No newline at end of file
src/SkyApm.Agent.GeneralHost/HostingEnvironmentProvider.cs
0 → 100644
View file @
e20d9a37
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You 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
Microsoft.Extensions.Hosting
;
namespace
SkyApm.Agent.GeneralHost
{
internal
class
HostingEnvironmentProvider
:
IEnvironmentProvider
{
public
string
EnvironmentName
{
get
;
}
public
HostingEnvironmentProvider
(
IHostingEnvironment
hostingEnvironment
)
{
EnvironmentName
=
hostingEnvironment
.
EnvironmentName
;
}
}
}
\ No newline at end of file
src/SkyApm.Agent.GeneralHost/InstrumentationHostedService.cs
0 → 100644
View file @
e20d9a37
/*
* Licensed to the SkyAPM under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The SkyAPM licenses this file to You 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.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Hosting
;
namespace
SkyApm.Agent.GeneralHost
{
internal
class
InstrumentationHostedService
:
IHostedService
{
private
readonly
IInstrumentStartup
_startup
;
public
InstrumentationHostedService
(
IInstrumentStartup
startup
)
{
_startup
=
startup
;
}
public
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
return
_startup
.
StartAsync
(
cancellationToken
);
}
public
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
return
_startup
.
StopAsync
(
cancellationToken
);
}
}
}
\ No newline at end of file
src/SkyApm.Agent.GeneralHost/SkyApm.Agent.GeneralHost.csproj
0 → 100644
View file @
e20d9a37
<Project Sdk="Microsoft.NET.Sdk">
<Import Project="..\..\build\common.props" />
<PropertyGroup>
<Description>$(Product) ASP.NET Core Agent.</Description>
<AssemblyTitle>$(PackagePrefix).Agent.GeneralHost</AssemblyTitle>
<AssemblyName>$(PackagePrefix).Agent.GeneralHost</AssemblyName>
<PackageId>$(PackagePrefix).Agent.GeneralHost</PackageId>
<PackageTags>SkyWalking;APM</PackageTags>
<PackageReleaseNotes>
</PackageReleaseNotes>
<RootNamespace>SkyApm.Agent.GeneralHost</RootNamespace>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.Extensions.Hosting.Abstractions" Version="2.1.0" PrivateAssets="All" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SkyApm.Abstractions\SkyApm.Abstractions.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql\SkyApm.Diagnostics.EntityFrameworkCore.Npgsql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql\SkyApm.Diagnostics.EntityFrameworkCore.Pomelo.MySql.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite\SkyApm.Diagnostics.EntityFrameworkCore.Sqlite.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.EntityFrameworkCore\SkyApm.Diagnostics.EntityFrameworkCore.csproj" />
<ProjectReference Include="..\SkyApm.Core\SkyApm.Core.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.HttpClient\SkyApm.Diagnostics.HttpClient.csproj" />
<ProjectReference Include="..\SkyApm.Diagnostics.SqlClient\SkyApm.Diagnostics.SqlClient.csproj" />
<ProjectReference Include="..\SkyApm.Transport.Grpc\SkyApm.Transport.Grpc.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Configuration\SkyApm.Utilities.Configuration.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.DependencyInjection\SkyApm.Utilities.DependencyInjection.csproj" />
<ProjectReference Include="..\SkyApm.Utilities.Logging\SkyApm.Utilities.Logging.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment