forked from SkyAPM/SkyAPM-dotnet
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1 from SkyAPM/master
add grpc skywalking (SkyAPM#236)
- Loading branch information
Showing
41 changed files
with
1,215 additions
and
13 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
36 changes: 36 additions & 0 deletions
36
sample/SkyApm.Sample.Backend/Controllers/GrpcController.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,36 @@ | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
using Microsoft.AspNetCore.Http; | ||
using Microsoft.AspNetCore.Mvc; | ||
using SkyApm.Sample.Backend.Services; | ||
|
||
namespace SkyApm.Sample.Backend.Controllers | ||
{ | ||
[Route("api/[controller]")] | ||
[ApiController] | ||
public class GrpcController : ControllerBase | ||
{ | ||
private readonly GreeterGrpcService _greeter; | ||
|
||
public GrpcController(GreeterGrpcService greeter) | ||
{ | ||
_greeter = greeter; | ||
} | ||
|
||
// GET api/values | ||
[HttpGet] | ||
public IEnumerable<string> Get() | ||
{ | ||
return new List<string> { "value1", "value2" }; | ||
} | ||
|
||
[HttpGet("greeter")] | ||
public async Task<IActionResult> SayHelloAsync(string name) | ||
{ | ||
var reply = await _greeter.SayHelloAsync(name); | ||
return Ok($"from backend grpc message{reply}"); | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
sample/SkyApm.Sample.Backend/Services/GreeterGrpcService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Grpc.Core; | ||
using Grpc.Core.Interceptors; | ||
using GrpcGreeter; | ||
using SkyApm.Diagnostics.Grpc.Client; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace SkyApm.Sample.Backend.Services | ||
{ | ||
public class GreeterGrpcService | ||
{ | ||
private readonly Greeter.GreeterClient _client; | ||
public GreeterGrpcService(ClientDiagnosticInterceptor interceptor) | ||
{ | ||
_client = new Greeter.GreeterClient(GetChannel(interceptor)); | ||
} | ||
|
||
private CallInvoker GetChannel(ClientDiagnosticInterceptor interceptor) | ||
{ | ||
var channel = new Channel("localhost:12345", ChannelCredentials.Insecure); | ||
var invoker = channel.Intercept(interceptor); | ||
return invoker; | ||
} | ||
|
||
public string SayHello(string name) | ||
{ | ||
var reply = _client.SayHello(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
|
||
public async Task<string> SayHelloAsync(string name) | ||
{ | ||
var reply = await _client.SayHelloAsync(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
|
||
public string SayHelloWithException(string name) | ||
{ | ||
var reply = _client.SayHelloWithException(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
|
||
public async Task<string> SayHelloWithExceptionAsync(string name) | ||
{ | ||
var reply = await _client.SayHelloWithExceptionAsync(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
51 changes: 51 additions & 0 deletions
51
sample/SkyApm.Sample.Frontend/Services/GreeterGrpcService.cs
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
using Grpc.Core; | ||
using Grpc.Core.Interceptors; | ||
using GrpcGreeter; | ||
using SkyApm.Diagnostics.Grpc.Client; | ||
using System; | ||
using System.Collections.Generic; | ||
using System.Linq; | ||
using System.Threading.Tasks; | ||
|
||
namespace SkyApm.Sample.Backend.Services | ||
{ | ||
public class GreeterGrpcService | ||
{ | ||
private readonly Greeter.GreeterClient _client; | ||
public GreeterGrpcService(ClientDiagnosticInterceptor interceptor) | ||
{ | ||
_client = new Greeter.GreeterClient(GetChannel(interceptor)); | ||
} | ||
|
||
private CallInvoker GetChannel(ClientDiagnosticInterceptor interceptor) | ||
{ | ||
var channel = new Channel("localhost:12345", ChannelCredentials.Insecure); | ||
var invoker = channel.Intercept(interceptor); | ||
return invoker; | ||
} | ||
|
||
public string SayHello(string name) | ||
{ | ||
var reply = _client.SayHello(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
|
||
public async Task<string> SayHelloAsync(string name) | ||
{ | ||
var reply = await _client.SayHelloAsync(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
|
||
public string SayHelloWithException(string name) | ||
{ | ||
var reply = _client.SayHelloWithException(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
|
||
public async Task<string> SayHelloWithExceptionAsync(string name) | ||
{ | ||
var reply = await _client.SayHelloWithExceptionAsync(new HelloRequest { Name = name }); | ||
return reply.Message; | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.