Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hawkly-grpc

Package Overview
Dependencies
Maintainers
1
Versions
16
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hawkly-grpc

An gRPC wrapper with an OpenTracing compatible tracer for hawkly.io

  • 0.5.3
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
1
decreased by-50%
Maintainers
1
Weekly downloads
 
Created
Source

hawkly gRPC wrapper for javascript

Repository | npm

codecov Build Status NSP Status

** Work in progress **

This is a wrapper around gRPC to add opentracing and async/await.

Usage

Server

Client

We provide a wrapper for the grpc client (based on a rewrite of https://www.npmjs.com/package/grpc-caller), which will automatically create a span and add it's context to the outgoing grpc call.

To create a client you need to pass options to instantiate both the Hawkly Tracer and the grpc client.

import {
  // Use this to create a new gRPC client from a proto file
  // This lets you call the services defined in the proto file
  createClient,
} from 'hawkly-grpc';

// defince your proto path
const PROTO_PATH: string = __dirname + '/helloworld.proto';

// create the client and tracer
const { tracer, client } = createClient(
  {
    // hawkly
    accessToken: 'get your token from hawkly.io',
    componentName: 'myComponent',
    // grpc
    host: grpcHost,
    proto: PROTO_PATH,
    name: 'Greeter',
  },
);

  // Create a new span to cover this unit of work
  const span: any = tracer.startSpan('myFirstSpan');

  // await the result of our gRPC call to `sayHello`
  // and an object of options to the call to specify the arg etc
  const request:Promise<any> = await client.sayHello({
    arg: { name: grpcHost },
    // pass the span we just created
    span,
  });

  // do stuff with result

  // finish our span
  span.finish();


Get the request Span

If you need access to the Span created for the request, you can pass in requestSpan:true to the options of the call. This will return you a tuple with request as a Promise and requestSpan and span as the span (both exist so you can use destructuring without having a local variable conflict with span).

import {
  // Use this to create a new gRPC client from a proto file
  // This lets you call the services defined in the proto file
  createClient,
  // request interface type
  TracedUnaryRequest,
} from 'hawkly-grpc';

  // await the result of our gRPC call to `sayHello`
  // and an object of options to the call to specify the arg etc
  const {request, requestSpan}:TracedUnaryRequest = await client.sayHello({
    arg: { name: grpcHost },
    // pass the span we just created
    span,
    requestSpan: true,
  });
  const result:any = await request;

More information

http://www.grpc.io/


hawkly.io Owen Kelly

Keywords

FAQs

Package last updated on 10 Mar 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc