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
af15d97d
Commit
af15d97d
authored
Apr 15, 2018
by
Liuhaoyang
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Init SkyWalking.AspNetCore project
parent
5c794442
Changes
11
Hide whitespace changes
Inline
Side-by-side
Showing
11 changed files
with
321 additions
and
15 deletions
+321
-15
skywalking-csharp.sln
skywalking-csharp.sln
+7
-0
AbstractTag.cs
src/SkyWalking.Abstractions/Context/Tag/AbstractTag.cs
+1
-1
HostingDiagnosticListener.cs
...lking.AspNetCore/Diagnostics/HostingDiagnosticListener.cs
+87
-0
ITracingDiagnosticListener.cs
...king.AspNetCore/Diagnostics/ITracingDiagnosticListener.cs
+25
-0
ServiceCollectionExtensions.cs
...king.AspNetCore/Extensions/ServiceCollectionExtensions.cs
+59
-0
SkyWalking.AspNetCore.csproj
src/SkyWalking.AspNetCore/SkyWalking.AspNetCore.csproj
+17
-0
SkyWalkingHostedService.cs
src/SkyWalking.AspNetCore/SkyWalkingHostedService.cs
+67
-0
SkyWalkingOptions.cs
src/SkyWalking.AspNetCore/SkyWalkingOptions.cs
+47
-3
SW3CarrierItem.cs
src/SkyWalking.Core/Context/SW3CarrierItem.cs
+1
-1
StringTag.cs
src/SkyWalking.Core/Context/Tag/StringTag.cs
+1
-1
Tags.cs
src/SkyWalking.Core/Context/Tag/Tags.cs
+9
-9
No files found.
skywalking-csharp.sln
View file @
af15d97d
...
...
@@ -28,6 +28,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Components", "Components",
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Core", "Core", "{CBFF7EE0-69D7-4D6A-9BBD-8E567FF4D810}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "SkyWalking.AspNetCore", "src\SkyWalking.AspNetCore\SkyWalking.AspNetCore.csproj", "{D75B68C5-6788-4871-A63F-F6EB48FB0DC5}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
...
...
@@ -54,6 +56,10 @@ Global
{50BE8184-EC7A-4257-AF54-764C0E61276F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{50BE8184-EC7A-4257-AF54-764C0E61276F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{50BE8184-EC7A-4257-AF54-764C0E61276F}.Release|Any CPU.Build.0 = Release|Any CPU
{D75B68C5-6788-4871-A63F-F6EB48FB0DC5}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{D75B68C5-6788-4871-A63F-F6EB48FB0DC5}.Debug|Any CPU.Build.0 = Debug|Any CPU
{D75B68C5-6788-4871-A63F-F6EB48FB0DC5}.Release|Any CPU.ActiveCfg = Release|Any CPU
{D75B68C5-6788-4871-A63F-F6EB48FB0DC5}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
...
...
@@ -66,6 +72,7 @@ Global
{FD84A10C-C962-4AEA-BA06-86F08EB048E6} = {CBFF7EE0-69D7-4D6A-9BBD-8E567FF4D810}
{54B9183A-928B-43E1-9851-10E2F1CCE61C} = {CBFF7EE0-69D7-4D6A-9BBD-8E567FF4D810}
{50BE8184-EC7A-4257-AF54-764C0E61276F} = {CBFF7EE0-69D7-4D6A-9BBD-8E567FF4D810}
{D75B68C5-6788-4871-A63F-F6EB48FB0DC5} = {79ED86A5-E9B9-49B2-9354-C911C079D03E}
EndGlobalSection
GlobalSection(ExtensibilityGlobals) = postSolution
SolutionGuid = {94C0DA2C-CCCB-4314-93A2-9809B5DD0583}
...
...
src/SkyWalking.Abstractions/Context/Tag/AbstractTag.cs
View file @
af15d97d
...
...
@@ -28,7 +28,7 @@ namespace SkyWalking.Context.Tag
Key
=
tagKey
;
}
p
rotected
abstract
void
Set
(
ISpan
span
,
T
tagValue
);
p
ublic
abstract
void
Set
(
ISpan
span
,
T
tagValue
);
/**
* @return the key of this tag.
...
...
src/SkyWalking.AspNetCore/Diagnostics/HostingDiagnosticListener.cs
0 → 100644
View file @
af15d97d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
;
using
Microsoft.AspNetCore.Http
;
using
Microsoft.Extensions.DiagnosticAdapter
;
using
SkyWalking.Context
;
using
SkyWalking.Context.Tag
;
using
SkyWalking.Context.Trace
;
namespace
SkyWalking.AspNetCore.Diagnostics
{
public
class
HostingDiagnosticListener
:
ITracingDiagnosticListener
{
public
HostingDiagnosticListener
()
{
}
public
string
ListenerName
{
get
;
}
=
"Microsoft.AspNetCore"
;
[
DiagnosticName
(
"Microsoft.AspNetCore.Hosting.HttpRequestIn"
)]
public
void
HttpRequestIn
()
{
// do nothing, just enable the diagnotic source
}
[
DiagnosticName
(
"Microsoft.AspNetCore.Hosting.HttpRequestIn.Start"
)]
public
void
HttpRequestInStart
(
HttpContext
httpContext
)
{
var
carrier
=
new
ContextCarrier
();
foreach
(
var
item
in
carrier
.
Items
)
item
.
HeadValue
=
httpContext
.
Request
.
Headers
[
item
.
HeadKey
];
var
httpRequestSpan
=
ContextManager
.
CreateEntrySpan
(
httpContext
.
Request
.
Path
,
carrier
);
httpRequestSpan
.
AsHttp
();
httpRequestSpan
.
SetComponent
(
"Asp.Net Core"
);
Tags
.
Url
.
Set
(
httpRequestSpan
,
httpContext
.
Request
.
Path
);
Tags
.
HTTP
.
Method
.
Set
(
httpRequestSpan
,
httpContext
.
Request
.
Method
);
}
[
DiagnosticName
(
"Microsoft.AspNetCore.Hosting.HttpRequestIn.Stop"
)]
public
void
HttpRequestInStop
(
HttpContext
httpContext
)
{
var
httpRequestSpan
=
ContextManager
.
ActiveSpan
;
var
statusCode
=
httpContext
.
Response
.
StatusCode
;
if
(
statusCode
>=
400
)
{
httpRequestSpan
.
ErrorOccurred
();
}
Tags
.
StatusCode
.
Set
(
httpRequestSpan
,
statusCode
.
ToString
());
ContextManager
.
StopSpan
(
httpRequestSpan
);
}
[
DiagnosticName
(
"Microsoft.AspNetCore.Diagnostics.HandledException"
)]
public
void
DiagnosticHandledException
(
HttpContext
httpContext
,
Exception
exception
)
{
ContextManager
.
ActiveSpan
.
ErrorOccurred
();
}
[
DiagnosticName
(
"Microsoft.AspNetCore.Diagnostics.UnhandledException"
)]
public
void
DiagnosticUnhandledException
(
HttpContext
httpContext
,
Exception
exception
)
{
ContextManager
.
ActiveSpan
.
ErrorOccurred
();
}
[
DiagnosticName
(
"Microsoft.AspNetCore.Hosting.UnhandledException"
)]
public
void
HostingUnhandledException
(
HttpContext
httpContext
,
Exception
exception
)
{
ContextManager
.
ActiveSpan
.
ErrorOccurred
();
}
}
}
\ No newline at end of file
src/SkyWalking.AspNetCore/Diagnostics/ITracingDiagnosticListener.cs
0 → 100644
View file @
af15d97d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.
*
*/
namespace
SkyWalking.AspNetCore.Diagnostics
{
public
interface
ITracingDiagnosticListener
{
string
ListenerName
{
get
;
}
}
}
\ No newline at end of file
src/SkyWalking.AspNetCore/Extensions/ServiceCollectionExtensions.cs
0 → 100644
View file @
af15d97d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
;
using
Microsoft.Extensions.Configuration
;
using
Microsoft.Extensions.DependencyInjection
;
using
Microsoft.Extensions.Hosting
;
using
SkyWalking.AspNetCore.Diagnostics
;
namespace
SkyWalking.AspNetCore
{
public
static
class
ServiceCollectionExtensions
{
public
static
IServiceCollection
AddSkyWalking
(
this
IServiceCollection
services
,
Action
<
SkyWalkingOptions
>
options
)
{
if
(
options
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
options
));
}
return
services
.
AddSkyWalking
().
Configure
(
options
);
}
public
static
IServiceCollection
AddSkyWalking
(
this
IServiceCollection
services
,
IConfiguration
configuration
)
{
return
services
.
AddSkyWalking
().
Configure
<
SkyWalkingOptions
>(
configuration
);
}
private
static
IServiceCollection
AddSkyWalking
(
this
IServiceCollection
services
)
{
if
(
services
==
null
)
{
throw
new
ArgumentNullException
(
nameof
(
services
));
}
services
.
AddSingleton
<
IHostedService
,
SkyWalkingHostedService
>();
services
.
AddSingleton
<
ITracingDiagnosticListener
,
HostingDiagnosticListener
>();
return
services
;
}
}
}
\ No newline at end of file
src/SkyWalking.AspNetCore/SkyWalking.AspNetCore.csproj
0 → 100644
View file @
af15d97d
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netstandard2.0</TargetFramework>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Hosting" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Http.Abstractions" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.AspNetCore.Mvc.Abstractions" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.DiagnosticAdapter" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Logging.Abstractions" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Options" Version="2.1.0-preview2-final" />
<PackageReference Include="Microsoft.Extensions.Options.ConfigurationExtensions" Version="2.1.0-preview2-final" />
</ItemGroup>
<ItemGroup>
<ProjectReference Include="..\SkyWalking.Core\SkyWalking.Core.csproj" />
</ItemGroup>
</Project>
\ No newline at end of file
src/SkyWalking.AspNetCore/SkyWalkingHostedService.cs
0 → 100644
View file @
af15d97d
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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
;
using
System.Collections.Generic
;
using
System.Diagnostics
;
using
System.Threading
;
using
System.Threading.Tasks
;
using
Microsoft.Extensions.Hosting
;
using
Microsoft.Extensions.Options
;
using
SkyWalking.AspNetCore.Diagnostics
;
using
SkyWalking.Boot
;
using
SkyWalking.Config
;
using
SkyWalking.Remote
;
namespace
SkyWalking.AspNetCore
{
public
class
SkyWalkingHostedService
:
IHostedService
{
public
SkyWalkingHostedService
(
IOptions
<
SkyWalkingOptions
>
options
,
IHostingEnvironment
hostingEnvironment
,
IEnumerable
<
ITracingDiagnosticListener
>
tracingDiagnosticListeners
,
DiagnosticListener
diagnosticListener
)
{
if
(
string
.
IsNullOrEmpty
(
options
.
Value
.
DirectServers
))
{
throw
new
ArgumentException
(
"DirectServers cannot be empty or null."
);
}
if
(
string
.
IsNullOrEmpty
(
options
.
Value
.
ApplicationCode
))
{
options
.
Value
.
ApplicationCode
=
hostingEnvironment
.
ApplicationName
;
}
AgentConfig
.
ApplicationCode
=
options
.
Value
.
ApplicationCode
;
CollectorConfig
.
DirectServers
=
options
.
Value
.
DirectServers
;
foreach
(
var
tracingDiagnosticListener
in
tracingDiagnosticListeners
)
diagnosticListener
.
SubscribeWithAdapter
(
tracingDiagnosticListener
);
}
public
async
Task
StartAsync
(
CancellationToken
cancellationToken
)
{
await
GrpcChannelManager
.
Instance
.
ConnectAsync
();
await
ServiceManager
.
Instance
.
Initialize
();
}
public
async
Task
StopAsync
(
CancellationToken
cancellationToken
)
{
GrpcChannelManager
.
Instance
.
ShutdownAsync
();
ServiceManager
.
Instance
.
Dispose
();
}
}
}
\ No newline at end of file
src/SkyWalking.AspNetCore/SkyWalkingOptions.cs
View file @
af15d97d
namespace
SkyWalking.AspNetCore
/*
* Licensed to the Apache Software Foundation (ASF) under one or more
* contributor license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright ownership.
* The ASF 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.Options
;
namespace
SkyWalking.AspNetCore
{
public
class
SkyWalkingOptions
public
class
SkyWalkingOptions
:
IOptions
<
SkyWalkingOptions
>
{
public
SkyWalkingOptions
Value
=>
this
;
/// <summary>
/// Application code is showed in sky-walking-ui
/// </summary>
public
string
ApplicationCode
{
get
;
set
;
}
/// <summary>
/// Collector agent_gRPC/grpc service addresses.
/// By using this, no discovery mechanism provided. The agent only uses these addresses to uplink data.
/// Recommend to use this only when collector cluster IPs are unreachable from agent side. Such as:
/// 1. Agent and collector cluster are in different VPC in Cloud.
/// 2. Agent uplinks data to collector cluster through Internet.
/// Single collector:DirectServers="127.0.0.1:11800"
/// Collector cluster:DirectServers="10.2.45.126:11800,10.2.45.127:11800"
/// </summary>
public
string
DirectServers
{
get
;
set
;
}
}
}
\ No newline at end of file
src/SkyWalking.Core/Context/SW3CarrierItem.cs
View file @
af15d97d
...
...
@@ -23,7 +23,7 @@ namespace SkyWalking.Context
public
class
SW3CarrierItem
:
CarrierItem
{
public
const
String
HEADER_NAME
=
"sw3"
;
private
IContextCarrier
_carrier
;
private
readonly
IContextCarrier
_carrier
;
public
SW3CarrierItem
(
IContextCarrier
carrier
,
CarrierItem
next
)
:
base
(
HEADER_NAME
,
carrier
.
Serialize
(),
next
)
...
...
src/SkyWalking.Core/Context/Tag/StringTag.cs
View file @
af15d97d
...
...
@@ -26,7 +26,7 @@ namespace SkyWalking.Context.Tag
{
}
p
rotected
override
void
Set
(
ISpan
span
,
string
tagValue
)
p
ublic
override
void
Set
(
ISpan
span
,
string
tagValue
)
{
span
.
Tag
(
Key
,
tagValue
);
}
...
...
src/SkyWalking.Core/Context/Tag/Tags.cs
View file @
af15d97d
...
...
@@ -24,46 +24,46 @@ namespace SkyWalking.Context.Tag
/// </summary>
public
static
class
Tags
{
public
static
StringTag
URL
=
new
StringTag
(
"url"
);
public
static
readonly
StringTag
Url
=
new
StringTag
(
"url"
);
/**
* STATUS_CODE records the http status code of the response.
*/
public
static
StringTag
STATUS_CODE
=
new
StringTag
(
"status_code"
);
public
static
readonly
StringTag
StatusCode
=
new
StringTag
(
"status_code"
);
/**
* DB_TYPE records database type, such as sql, redis, cassandra and so on.
*/
public
static
StringTag
DB_TYPE
=
new
StringTag
(
"db.type"
);
public
static
readonly
StringTag
DbType
=
new
StringTag
(
"db.type"
);
/**
* DB_INSTANCE records database instance name.
*/
public
static
StringTag
DB_INSTANCE
=
new
StringTag
(
"db.instance"
);
public
static
readonly
StringTag
DbInstance
=
new
StringTag
(
"db.instance"
);
/**
* DB_STATEMENT records the sql statement of the database access.
*/
public
static
StringTag
DB_STATEMENT
=
new
StringTag
(
"db.statement"
);
public
static
readonly
StringTag
DbStatement
=
new
StringTag
(
"db.statement"
);
/**
* DB_BIND_VARIABLES records the bind variables of sql statement.
*/
public
static
StringTag
DB_BIND_VARIABLES
=
new
StringTag
(
"db.bind_vars"
);
public
static
readonly
StringTag
DbBindVariables
=
new
StringTag
(
"db.bind_vars"
);
/**
* MQ_BROKER records the broker address of message-middleware
*/
public
static
StringTag
MQ_BROKER
=
new
StringTag
(
"mq.broker"
);
public
static
readonly
StringTag
MqBorker
=
new
StringTag
(
"mq.broker"
);
/**
* MQ_TOPIC records the topic name of message-middleware
*/
public
static
StringTag
MQ_TOPIC
=
new
StringTag
(
"mq.topic"
);
public
static
readonly
StringTag
MqTopic
=
new
StringTag
(
"mq.topic"
);
public
static
class
HTTP
{
public
static
readonly
StringTag
M
ETHOD
=
new
StringTag
(
"http.method"
);
public
static
readonly
StringTag
M
ethod
=
new
StringTag
(
"http.method"
);
}
}
}
\ 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