async request()

in src/Transport.ts [676:713]


  async request<TResponse = unknown> (params: TransportRequestParams, options?: TransportRequestOptionsWithOutMeta): Promise<TResponse>
  async request<TResponse = unknown, TContext = any> (params: TransportRequestParams, options?: TransportRequestOptionsWithMeta): Promise<TransportResult<TResponse, TContext>>
  async request<TResponse = unknown> (params: TransportRequestParams, options?: TransportRequestOptions): Promise<TResponse>
  async request (params: TransportRequestParams, options: TransportRequestOptions = {}): Promise<any> {
    // wrap in OpenTelemetry span
    if (params.meta?.name != null) {
      // gather OpenTelemetry attributes
      const attributes: Attributes = {
        'db.system': 'elasticsearch',
        'http.request.method': params.method,
        'db.operation.name': params.meta?.name
      }
      if (params.meta?.pathParts != null) {
        for (const key of Object.keys(params.meta.pathParts)) {
          attributes[`db.elasticsearch.path_parts.${key}`] = params.meta.pathParts[key]
        }
      }

      return await this[kOtelTracer].startActiveSpan(params.meta.name, { attributes, kind: SpanKind.CLIENT }, async (otelSpan: Span) => {
        let response
        try {
          response = await this._request(params, options, otelSpan)
        } catch (err: any) {
          otelSpan.recordException(err as Exception)
          otelSpan.setStatus({ code: SpanStatusCode.ERROR })
          otelSpan.setAttribute('error.type', err.name ?? 'Error')

          throw err
        } finally {
          otelSpan.end()
        }

        return response
      })
    } else {
      return await this._request(params, options)
    }
  }