/// <inheritdoc />
        public async Task UpsertFunctionAsync(EventingFunction function, UpsertFunctionOptions options = null)
        {
            //POST http://localhost:8096/api/v1/functions/<name>;
            options ??= UpsertFunctionOptions.Default;

            var path = $"/api/v1/functions/{Uri.EscapeDataString(function.Name)}";

            try
            {
                using var rootSpan = RootSpan(OuterRequestSpans.ManagerSpan.Eventing.UpsertFunction, options)
                                     .WithLocalAddress()
                                     .WithStatement(path)
                                     .WithCommonTags();

                using var encodeSpan = rootSpan.DispatchSpan(options);
                using (var tokenPair = CreateRetryTimeoutCancellationTokenSource(options))
                {
                    using var response = await _service.PostAsync(path, rootSpan, encodeSpan, tokenPair.GlobalToken, function)
                                         .ConfigureAwait(false);

                    if (response.IsSuccessStatusCode)
                    {
                        return;
                    }

                    var content = await response.Content.ReadAsStringAsync().ConfigureAwait(false);

                    if (content.TryDeserialize <ErrorResponse>(out var errorResponse))
                    {
                        switch (errorResponse.Name)
                        {
                        case "ERR_HANDLER_COMPILATION":
                            throw new EventingFunctionCompilationFailureException(errorResponse.GetDescription());

                        case "ERR_COLLECTION_MISSING":
                            throw new CollectionNotFoundException(errorResponse.GetDescription());

                        case "ERR_SRC_MB_SAME":
                            throw new EventingFunctionIdenticalKeyspaceException(errorResponse.GetDescription());

                        case "ERR_BUCKET_MISSING":
                            throw new BucketNotFoundException(errorResponse.GetDescription());

                        case "ERR_INVALID_CONFIG":
                            throw new InvalidArgumentException(errorResponse.GetDescription());
                        }
                    }

                    //throw any non-specific errors
                    throw new CouchbaseException(content);
                }
            }
            catch (Exception e)
            {
                _logger.LogError(e, $"An error occurred while upserting event function {function.Name}.");
                throw;
            }
        }
        /// <inheritdoc />
        public Task <HttpResponseMessage> PostAsync(string path, IRequestSpan parentSpan, IRequestSpan encodeSpan, CancellationToken token, EventingFunction eventingFunction = null)
        {
            var requestUri = GetUri(path);

            parentSpan.WithRemoteAddress(requestUri);

            var content = eventingFunction != null ?
                          new StringContent(eventingFunction.ToJson()) :
                          new StringContent(string.Empty);

            encodeSpan.Dispose();
            using var dispatchSpan = parentSpan.DispatchSpan();
            var httpClient = CreateHttpClient();

            return(httpClient.PostAsync(requestUri, content, token));
        }