https://github.com/instabug/instabug-grpc
https://github.com/instabug/instabug-grpc
Last synced: 6 days ago
JSON representation
- Host: GitHub
- URL: https://github.com/instabug/instabug-grpc
- Owner: Instabug
- Created: 2022-01-11T14:25:14.000Z (over 3 years ago)
- Default Branch: main
- Last Pushed: 2023-12-06T14:40:21.000Z (over 1 year ago)
- Last Synced: 2025-06-20T07:04:09.955Z (8 days ago)
- Language: Swift
- Size: 36.1 KB
- Stars: 0
- Watchers: 7
- Forks: 0
- Open Issues: 1
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# Instabug-gRPC
This is a destination for Instabug to support logging gRPC requests.## Compatibility
There's `Instabug_gRPC_Swift` which is a Swift framework and intended to be used with Swift projects. And there's `Instabug_gRPC_Objc` which intended to be used with Objective-C projects## Installation
Add pod `Instabug-gRPC-Swift` or pod `'Instabug-gRPC-ObjC'` to your `podfile`
## Requirements
iOS version >= 10.0
Instabug version >= 10.11.8## Swift Example
1. Make sure you import our destination first: `import Instabug_gRPC_Swift`
2. Create Interceptor factory that confirms to the interceptor factory protocol that you have in your .grpc file
3. Make sure to return new instance of our Interceptor `InstabugClientInterceptor()` in the methods that you need us to log
4. Conform on `InstabugGRPCDataProtocol` for request and response models which requires that you expose your models as `Data`
5. You can convert your model to `Data` by conforming to `Encodable`
6. You can pass the port optional in `InstabugClientInterceptor` as `InstabugClientInterceptor(port:)` to see it on the dashboard
### Sample code```
class ExampleClientInterceptorFactory: Echo_EchoClientInterceptorFactoryProtocol {
// Returns an array of interceptors to use for the 'Get' RPC.
func makeGetInterceptors() -> [ClientInterceptor] {
return [InstabugClientInterceptor()]
}// Returns an array of interceptors to use for the 'Expand' RPC.
func makeExpandInterceptors() -> [ClientInterceptor] {
return [InstabugClientInterceptor()]
}// Returns an array of interceptors to use for the 'Collect' RPC.
func makeCollectInterceptors() -> [ClientInterceptor] {
return [InstabugClientInterceptor()]
}// Returns an array of interceptors to use for the 'Update' RPC.
func makeUpdateInterceptors() -> [ClientInterceptor] {
return [InstabugClientInterceptor()]
}
}extension GrpcAutomation_RepeaterRequest: InstabugGRPCDataProtocol, Encodable {
enum CodingKeys: String, CodingKey {
case message, unknownFields
}
public func encode(to encoder: Encoder) throws {
var container = encoder.container(keyedBy: CodingKeys.self)
try container.encode(message, forKey: .message)
}
public var gRPCRequestData: Data? {
let jsonEncoder = JSONEncoder()
let data = try? jsonEncoder.encode(self)
return data
}
```And finally pass `ExampleClientInterceptorFactory()` to your client like this
```
let client = Echo_EchoClient(channel: channel, interceptors: ExampleClientInterceptorFactory())
```## ObjectiveC Example
1. Create an array of `GRPCInterceptorFactory`
2. Create a class that conforms to `GRPCInterceptorFactory` protocol```
@interface GRPCFactory : NSObject
```3. Override `createInterceptorWithManager` in `GRPCFactory` and return `InstabugClientInterceptor `
```
- (nonnull GRPCInterceptor *)createInterceptorWithManager:(nonnull GRPCInterceptorManager *)interceptorManager {
InstabugClientInterceptor *interceptor = [[InstabugClientInterceptor alloc] initWithInterceptorManager:interceptorManager dispatchQueue:dispatch_get_main_queue()];
return interceptor;
}
```
4. Create a new instance from `GRPCFactory` then add it to the interceptors array
5. Create a new instance of `GRPCInterceptorManager` with the `interceptorFactories` array
6. Then pass the manager to the factory instance then
7. Finally pass `interceptorFactories` to `options.interceptorFactories`### Sample code
```
GRPCMutableCallOptions *options = [[GRPCMutableCallOptions alloc] init];
NSMutableArray> *interceptorFactories = [NSMutableArray new];
GRPCFactory *factory = [GRPCFactory new];
[interceptorFactories addObject:factory];
GRPCInterceptorManager *manager = [[GRPCInterceptorManager alloc] initWithFactories:interceptorFactories
previousInterceptor:nil
transportID:GRPCDefaultTransportImplList.core_insecure];[factory createInterceptorWithManager:manager];
options.interceptorFactories = interceptorFactories;```